aximbigfan Posted April 23, 2008 Share Posted April 23, 2008 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 More sharing options...
ucffool Posted April 23, 2008 Share Posted April 23, 2008 Simply have the form POST to the other page, which processes the information, then POSTS it back to your page. Here is one page with an example. Link to comment https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/#findComment-524691 Share on other sites More sharing options...
aximbigfan Posted April 23, 2008 Author Share Posted April 23, 2008 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 Link to comment https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/#findComment-524992 Share on other sites More sharing options...
ucffool Posted April 23, 2008 Share Posted April 23, 2008 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'); Link to comment https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/#findComment-525159 Share on other sites More sharing options...
aximbigfan Posted April 24, 2008 Author Share Posted April 24, 2008 Anyone? Chris Link to comment https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/#findComment-525647 Share on other sites More sharing options...
aximbigfan Posted April 24, 2008 Author Share Posted April 24, 2008 Never mind, fixed it. I forgot the change the request type in the script that receives input. Chris Link to comment https://forums.phpfreaks.com/topic/102457-use-php-to-post-to-other-php-script/#findComment-525680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.