Jump to content

Use PHP to post to other PHP script...


aximbigfan

Recommended Posts

I have 2 PHP scripts, and they need to talk to each other. They reside on different servers. Up until now, I have been doing this to get what the other PHP script says

 

file_get_contents("http://myurl/myfile.php?x=x&y=y");

 

the problem is that I am now needing to send very large amounts of data back and forth, and I cannot do this with the get var.

 

How can I...

Post to a PHP script?

Then get the outcome?

 

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/
Share on other sites

Ok, I have this but nothing ever gets posted.

All that is returned is "HTTP 200 OK", and a POST does appear in the access log, but the script does not receive any data.

function contactrdb($host, $path, $data)
{
$http_response  = "";
$content_length = strlen($data);
$fp             = fsockopen($host, 80);
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-rlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp))
$http_response .= fgets($fp, 28);
fclose($fp);
return $http_response;
}

function post_prep($data)
{
global $DBHOST, $KEYCAT, $KEYNAME, $SVRURL; 
return contactrdb($DBHOST, $SVRURL, "?mode=W&cat=$KEYCAT&key=$KEYNAME&val=$data");
}

 

Thanks,

Chris

I suppose I used the term simply too loosely. It's a pain in the butt, but as you show, possible. I haven't done it myself before, so I'd have to run some testing on the code to see. However, I know that POST has a larger limit thank GET, but trying it this way, can you send the data through GET?

$array = ();
$array['variablename'] = 'value';
// Do this for each bit of info you need to send along
$querystring = http_build_query($array); // creates a URL-encoded string
header(Location: 'http://www.example.com/catchme.php$querystring');

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.