Tuesday, January 22, 2008

Curl Example & fsockopen() Example

***************************** CURL Example ****************************



$senthost = "http://s4.myvaluefirst.com/psms/servlet/psms.Eservice2?data=".$xmlcode."&action=send";
//echo "Path:".$path."
";
//print $path."
";
$user_agent=$_SERVER['HTTP_USER_AGENT'];
$cookies = 'cookies';
$ch = curl_init($senthost);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$line = curl_exec($ch);
$error = curl_error($ch);
echo (($error!= "")? ('Error: ' . $error) : $line);
curl_close($ch);


******************************** Getting with fsockopen() function

$senthost = "http://localhost/loginvalidate.php?username=demo&pass=123";

$host="127.0.0.1";
$http = fsockopen($host,80,$errono,$errstr);//must
if($errno)
{
$content .= "Error No. : ".$errno." Error : ".$errstr."
".$fp."";
}
else
{
if ($http)
{
$req = "GET $senthost HTTP/1.2\r\n ";
$req .= "Host: 61.8.156.62\r\n";
$req .= "Connection: Close\r\n\r\n";
fputs($http, $req); //must
// Output the request results

$x_return_code;
$line="";
while(!feof($http)) //must
{
//$x_return_code=$RETURN_CODE;
$line .= fgets($http,1024);
//echo fgets($http, 1024);
//$data=fgets($http,1024);
}

}

No comments: