validation - PHP - get a page content with fsockopen (skype username check)? -


i've fsockopen on server use. mean can't use curl or file_get_contents. i'm using php way

i want have skype user name validation, found link other topic:

https://login.skype.com/json/validator?new_username=anyusername

this page responses valid or invalid username json output: {"status":200,"status_text":"valid","data":{"markup":"","alternatives":false,"fielddetails":""}}

it says valid, username not exist. may parse data see whether it's correct.

my question is, how can https page content fsockopen, can open socket try read data failed many times many snippets got forums. because i've no idea how it, if can't write code please tell me or show me way it?

basicly, how return skype id status fsockopen in php, i'll glad comments, in advance guys.

if have openssl in php, should able prefix hostname or ip 'ssl://' or 'tls://' proper port number , php should handle rest. this:

fsockopen('ssl://78.141.177.180', 443, $errno, $errstr); 

and use returned resource usual. myself use function bellow when no curl available (code salvaged php.net comment , massaged little). call like

not_curl_get('login.skype.com/json/validator?new_username=foo', 'ssl://', 443) 

the function itself:

function not_curl_get($url, $protocol = '', $port = 80, $options = array()) {     $options = array_merge(array(         'follow_location'      => true,         'return_response_part' => 'body',         'referer'              => false,         'user_agent'           => 'mozilla/5.0 (windows; u; windows nt 5.1; hu; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 (.net clr 3.5.30729)',         'cookie_file'          => false,         'request_type'         => 'get',     ), $options);      global $_not_curl_get_oldheader;     $url = str_replace("http://","",$url);     if (preg_match("#/#","$url")){         $page = $url;         $url = @explode("/",$url);         $url = $url[0];         $page = str_replace($url,"",$page);         if (!$page || $page == ""){             $page = "/";         }         $ip = gethostbyname($url);     }else{         $ip = gethostbyname($url);         $page = "/";     }     $open = fsockopen($protocol.$ip, $port, $errno, $errstr, 60);     if ($options['request_type'] === 'post'){         $send = "post $page http/1.0\r\n";     }else{         $send = "get $page http/1.0\r\n";     }     $send .= "host: $url\r\n";     if ($options['referer']){         $send .= "referer: ".$options['referer']."\r\n";     }     if ($options['cookie_file']){         if (@file_exists($options['cookie_file'])){             $cookie = urldecode(@file_get_contents($options['cookie_file']));             if ($cookie){                 $send .= "cookie: $cookie\r\n";                 $add = @fopen($options['cookie_file'],'w');                 fwrite($add,"");                 fclose($add);             }         }     }     $send .= "accept-language: en-us, en;q=0.50\r\n";     if ($options['user_agent']){         $send .= "user-agent: ".$options['user_agent']."\r\n";     }     if ($options['request_type']){         $send .= "content-type: application/x-www-form-urlencoded\r\n";         $send .= "content-length: " .strlen($options['request_type']) ."\r\n\r\n";         $send .= $options['request_type'];     }else{         $send .= "connection: close\r\n\r\n";     }     fputs($open, $send);     $return = '';     while (!feof($open)) {         $return .= fgets($open, 4096);     }     fclose($open);     $return = @explode("\r\n\r\n",$return,2);     $header = $return[0];     if ($options['cookie_file']){         if (preg_match("/set\-cookie\: /i","$header")){             $cookie = @explode("set-cookie: ",$header,2);             $cookie = $cookie[1];             $cookie = explode("\r",$cookie);             $cookie = $cookie[0];             $cookie = str_replace("path=/","",$cookie[0]);             $add = @fopen($options['cookie_file'],'a');             fwrite($add,$cookie,strlen($read));             fclose($add);         }     }     if ($_not_curl_get_oldheader){         $header = "$_not_curl_get_oldheader<br /><br />\n$header";     }     if ($return[1]){         $body = $return[1];     }else{         $body = "";     }     if ($options['return_response_part'] === 'body'){         $return = $body;     }     if ($options['return_response_part'] === 'head'){         $return = $header;     }     if ($options['return_response_part'] === 'all'){         $return = "$header$body";     }     if ($options['follow_location']){         if (preg_match("/location\:/","$header")){             $url = @explode("location: ",$header);             $url = $url[1];             $url = @explode("\r",$url);             $url = $url[0];             $_not_curl_get_oldheader = str_replace("\r\n\r\n","",$header);             $l = "&#76&#111&#99&#97&#116&#105&#111&#110&#58";             $_not_curl_get_oldheader = str_replace("location:",$l,$_not_curl_get_oldheader);             return not_curl_get($url, $protocol, $port, $options);         }else{             return $return;         }     }else{         return $return;     } } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -