Jump to content

fsockopen help, for ipn


gandaliter

Recommended Posts

Hi,

 

I am setting up a site selling web hosting, and it runs through paypal, I managed to get the socket working for ipn (requires a post back for validation). However, to enable automatic activation of the hosting account, I need to do another, custom, post. I found a function somewhere to do this. It is as follows.

 

function HTTP_Post($URL, $dat, $referrer="", $get = 0)
{
// parsing the given URL
$URL_Info=parse_url($URL);

// Building referrer
if($referrer=="") // if not given use this script as referrer
$referrer=$_SERVER["SCRIPT_URI"];

// making string from $data
foreach($dat as $key=>$value) $values[]="$key=".urlencode($value);
$data_string=implode("&",$values);

// Find out which port is needed - if not given use standard (=443)
if(!isset($URL_Info["port"])) $URL_Info["port"] = 80;

// building POST-request:
if ($get == 1)
{
$request.="GET ".$URL_Info["path"]." HTTP/1.1\n";
}
else
{
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
}
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";

$result = '';
if ($fp = fsockopen("http://" . $URL_Info["host"], $URL_Info["port"],
$errno, $errstr, 2.0))
{
fputs($fp, $request);
while((!feof($fp)))
{
$result .= @fgets($fp, 128);
}
fclose($fp);
}
return $result;
}

 

I gathered that the idea would be that you could type in something like '$info = HTTP_POST('www.domainname.com/path/page.php',$array);' where $array was an array of post vars, I also changed it a bit so that $get could be set to use get vars instead of post vars. The problem seems to be that the parsing of the url doesn't work, but if you alter that so that it doesn't need to be parsed you get other errors.

 

Thanks for your help,

 

Toby Miller

Link to comment
https://forums.phpfreaks.com/topic/48277-fsockopen-help-for-ipn/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.