Page 1 of 1
Server to Server call
Posted: Thu Dec 13, 2007 10:35 am
by ed209
Hi,
I have a PayPal IPN script that needs to send an affiliate tracker some variables via GET.
I basically need to do a server to server call with this URL:
http://www.someurl.com/amount=4.99&code ... ans=inv123
I'm not sure what I need use, I don't expect to get anything back from that call. Would I use:
Code: Select all
$url = "www.someurl.com/amount=4.99&code=abc123&trans=inv123";
$fp = fsockopen($url, 80, $errno, $errstr, 30);
is it that simple?
Thanks
Posted: Thu Dec 13, 2007 10:45 am
by feyd
It's slightly more complicated than that, but not much more.
You will only have the server in $url. You will need to write a few headers to it once you have $fp. They will, at least need to be similar to the following.
Code: Select all
HTTP/1.0
GET /amount=4.99&code=abc123&trans=inv123
SERVER www.someurl.com
Posted: Tue Dec 18, 2007 4:44 am
by ed209
how does this look? Unfortunately, they don't have anywhere to test it so I'd like to try and get the code correct before using it. Thanks in advance.
Code: Select all
$p36 = some number;
$transId = some id;
$amount = some amount;
$url = "www.someurl.com";
$file = "/pathto/processingScript.php";
$get = "VAR1=123&AMOUNT=" . $amount . "&TRANSID=" . $transId . "&P36=" . $p36;
$header = "GET " . $file . "?" . $get . " HTTP/1.0\r\n";
$header .= "User-Agent: PHP/".phpversion()."\r\n";
$header .= "Referer: ".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
$header .= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
$header .= "Host: " . $url . ":80\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($get)."\r\n";
$header .= "Accept: */*\r\n\r\n";
$fp = fsockopen ($url, 80, $errno, $errstr, 30);
fwrite ($fp, $header);
while (!feof($fp)) {
$ret = fgets($fp, 128);
}
fclose ($fp);
if ( !$ret ) {
// error message
}
edit: I have tried using the above but it doesn;t seem to work. However, going to the URL directly in a browser does work:
http://www.someurl.com/pathto/processin ... P36=abc123
so I think it's my code...
Posted: Tue Dec 18, 2007 7:42 am
by feyd
Have you looked into using Snoopy?
http://snoopy.sf.net
Posted: Tue Dec 18, 2007 7:46 am
by Ollie Saunders
Isn't curl better/easier for this sort of thing?
Posted: Tue Dec 18, 2007 10:04 am
by deadoralive
also if you're looking to put test transactions through try
http://developer.paypal.com
Posted: Tue Dec 18, 2007 10:26 am
by ed209
thanks for help. All I'm trying to do is to call a URL from my php script - I'm not expecting anything back. All I need to do is to call a URL like this:
http://www.someaddress.com/path/toProce ... c&var2=123
I have based the code on the PayPal IPN script for PHP, but I actually need it for an affiliate tracking scheme. I'll give snoopy a try and post back.
thanks.
edit: Snoopy did the job, 2 lines of code! thanks.