Hello-
I'm trying to use a listener file to get just two POST variables from a verified transaction and then create two sessions from my two variables, but I can't get it to work. The nothing is returned and the sessions are never created. My code is below. I modified the sample listener from the PatyPal site. I have IPN turned on and pointing to this file. Can anyone tell me what I have wrong? Thanks.

session_start(); 

// Read the post from PayPal and add 'cmd' 
$req = 'cmd=_notify-validate'; 
if(function_exists('get_magic_quotes_gpc')) 
{  
$get_magic_quotes_exits = true; } foreach ($_POST as $key => $value) // Handle escape characters, which depends on setting of magic quotes {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1){
$value = urlencode(stripslashes($value)); } else { $value = urlencode($value); } $req .= "&$key=$value"; } // Post back to PayPal to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30); // Process validation from PayPal // TODO: This sample does not test the HTTP response code. All // HTTP response codes must be handles or you should use an HTTP // library, such as cUrl if (!$fp) { // HTTP ERROR } else { // NO HTTP ERROR fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { $transactionID=$_POST["txn_id"]; $item_number=$_POST["item_number"]; session_register("package"); $_SESSION["package"] = $item_number; session_register("order_number"); $_SESSION["order_number"] = $transactionID; } else if (strcmp ($res, "INVALID") == 0) { echo ("INVALID"); } } } fclose ($fp);

    If I were you, I would try visiting this script of yours in a browser to make sure it doesn't have any syntax errors. If you made one little mistake then it's not going to work.

    I'd also make a temporary mod to write your $POST data to a file to make sure that paypal is in fact calling this page:

    file_put_contents('log_file.txt', print_r($_POST, TRUE));
    

    Once you are sure that Paypal is really sending data to your page, you'll have a better chance of debugging your script.

    If it's not working at that point, then it could be because that script snippet opens a raw socket connection back to paypal using [man]fsockopen[/man]. I think you need to have the sockets extension installed for that.

    Also, read the docs on [man]session_register[/man]. I don't it does what you think it does.

      you can use the paypal sandbox to test transactions. humans don't hit the ipn script a bot does, so there's no use in using sessions.

        Write a Reply...