RE: How to forward a POSTed form to another server and catch the return for further processing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi

this should do the trick

Peter



// this is the script to pass the post onto
$server_to_post_to = 'http://www.test.com/somescript.php';

$url         = parse_url($server_to_post_to);
unset($request_data) ;

//run through the data POSTed to this server and build a new POST request

foreach ($_POST as $name => $value)
{
   if (strlen($request_data) > 0)  $request_data .= '&';
   
   $request_data .= $name.'='.urlencode($value);
} 

//create a new post to the other sever
$request    = "POST ".$url['path']." HTTP/1.1\r\n".
               "Host: ".$url['host']."\r\n".
               "Content-type: application/x-www-form-urlencoded\r\n".
               "Content-length: ".strlen($request_data)."\r\n\r\n".
               $request_data;
               


// Open the connection 
$fp = fsockopen($url['host'], 80, $err_num, $err_msg, 30); 

if ($fp) 
    {
       // Submit form
       fputs($fp, $request);
       
       // Get the response 
       while (!feof($fp)) 
        {
          $response .= fgets($fp,1024);
        }
        
       fclose($fp);
       //do somthing with $response here
       
    }
else
    {
    //could not connect to  server
    print 'Error '.$err_num.' '.$err_msg;
    }







> -----Original Message-----
> From: Yanglong Zhu [mailto:yanglong@xxxxxxxxx]
> Sent: 15 August 2004 01:41
> To: php-db@xxxxxxxxxxxxx
> Subject:  How to forward a POSTed form to another server and
> catch the return for further processing
> 
> 
> How to forward a POSTed form to another server and
> catch the return for further processing.
> 
> I think I did this before. But now I have completely
> forgot how that was done. The posted form data is
> processed on the other server, the results should be
> returned or captured by the first server. Obviously my
> brain is not working.
> 
> Thanks for your help.
> 
> 
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 50x more storage than other providers!
> http://promotions.yahoo.com/new_mail
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux