php - API - is the connection secure? -
how check if connection rest api secure?
1) i'm building api , want make sure connection running ssl before response generated , returned client.. username , password passed in every request
2) , how can make fsockopen connection ssl?
$this->url = 'api.domain.com'; $this->path = '/v1/json/account/user/pass/?id=123'; if($this->fp = fsockopen($this->url, $this->port, $errno, $errstr, $this->timeout)){ $write = "$this->method $this->path http/1.1\r\n"; $write .= "host: $this->url\r\n"; $write .= "content-type: $this->content_type\r\n"; $write .= "connection: close\r\n\r\n"; fwrite($this->fp, $write); while($line = fgets($this->fp)){ if($line !== false) $this->response .= $line; } fclose($this->fp); }
just check $_server['https']
.
the php manual @ http://php.net/manual/en/reserved.variables.server.php says:
'https'
set non-empty value if script queried through https protocol.
note: note when using isapi iis, value off if request not made > through https protocol.
Comments
Post a Comment