Hi i am relative new to php,
on my own apache server (localhost), i use one .php script to 'post' data to another .php script, which is also on my server. I cannot receive the posted data.

The code on the sending page is:

# $req = "&One=Ena&Two=Dyo&Three=Tria";
# $req = urlencode($req);
# $header = "POST /main/php/Receive.php HTTP/1.1\r\n";
# $header .= "Host: localhost\r\n";
# $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
# $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
# $header .= $req;
#  
#  
# $fp = fsockopen ('localhost', 8000, $errno, $errstr,2);
#              if (!$fp) { $message ="// HTTP connection ERROR!"; echo $message; exit;}
#              else {
#                   fputs ($fp, $header);
#                   echo "Success on fputs!<br/>";
#  
#                   while (!feof($fp) )
#                       {
#                        $res[$i] = fgets($fp,1024);
#                        echo "RESULTs :".count($res)."<br/>";
#                        echo 'Res['.$i.'] ='.$res[$i]."<br/>";
#                        $i++;
#                       }
#                  }
# fclose($fp);

while the code on the receiving script is:

# $result = 'NULL';
#  
# foreach( $_POST as $key => $value ) // also tried $_REQUEST
#                 { $result .= $value; }
# ///// then i write the $result on a MYSQL table

On each execution of the sending script, the receiving script is triggered. I know this, because a new insertion of $result is entered in mysql after the sending script is executed, but it is allways an emty string.
I checked the $_POST with other ways also, but it still shows empty.
Please advise what am i doing wrong. Any help appreciated.

    I've not worked with the socket stuff, but if you don't get a resolution, I thought of a potential work-around:

    In the calling script, add the data to be posted to the $_POST array there, then simple include/require the 2nd script. Seems like it might work, depending of course on what else the 2nd script requires/does.

      Why are you using post to pass vars around your own site? Unless its a form i dont see the point.

        Hi NogDog, hi Dagon,
        thank you for your reply.

        The reason i want the data to be sent through the fsockopen, is because
        that is the core procedure paypal uses for its IPN (instant payment notification).
        I want to understand it, in its simplest form (i.e between my two own scripts), because it doesn't work with paypal in the first place.
        It seems that i can't make it work at all!

          Maybe try the [man]cURL[/man] functions?

            I have read about curl and it is a great versatille tool. But as i mentioned the
            fsockopen method is used by paypal for IPN, which i am interested right now.
            So what am i doing wrong with the fsockopen?
            I even tried to send a simple string without the & and =, but is still doesn't work.

              Hi NogDog,

              i only wanted to report that the issue is solved.
              The problem was the missuse of urlencoding function:
              Wrong way:

              $req = "One=$var1&Two=$var2&Three=$var3";
              $req = urlencoding($req);

              Correct way:

              $req = "One=".urlencoding($var1)."&Two=".urlencoding($var2)."&Three=".urlencoding($var3);

              Thanks for helping anyway
              Pelasgos

                paypal has a sand box for testing, it will be easier than using your own site.

                  Write a Reply...