Page 1 of 1

Running a script from an other server through php

Posted: Tue Nov 23, 2004 1:18 pm
by nyk
I have a main server with the main php "portal" script.
On an others server, there is a perl CGI, that I'm not allowed to run on the main server.

Now I'd like to let the main php script run the perl script on that other server. It would receive the POST/GET parameters and would pass them (though a user-agent) to the perl script and also dispay the output to the user.
In the perl script I would just have to change the path to itself, but I don't know how to do the user-agent stuff in php, or if there is a simpler way to this. Anyone got an idea?

Posted: Tue Nov 23, 2004 4:32 pm
by rehfeld
fsockopen()

ini_set('user_agent', 'msie 5.0 etc...');

Posted: Thu Nov 25, 2004 10:12 am
by nyk
thanx, it works!

Code: Select all

function tor() {
	$PARAM=array_merge($_GET,_POST);
	foreach ($PARAM as $key => $value) {
		if ($key) {$p="$p&$key=$value";}
	}
	$p=preg_replace("/^\&/","?",$p);
	$fp = fsockopen ("host.whereit.is", 80, $errno, $errstr, 30);
	if (!$fp) {
	    echo "$errstr ($errno)<br>\n";
	&#125; else &#123;
	    fputs ($fp, "GET /cgi-bin/tor.cgi$p HTTP/1.1\nHost: host.whereit.is\r\n\r\n");
	    while (!$off) &#123;
	        $b=fgets ($fp,128);
		if (preg_match("/bodystart/i",$b)) &#123;$on=1;&#125;
		if ($on) &#123;print $b;&#125;
		if (preg_match("/bodyende/i",$b)) &#123;$off=1;$on=0;&#125;

	    &#125;
	    fclose ($fp);
	&#125;
&#125;
the only strange thing is that while (!feof) didn't work, just keept waiting for something after the file was finished. so I had to insert my own EOF marker.

AND WHATS WORSE:
I get random "1000" strings in the text I receive!!!!!

Posted: Thu Nov 25, 2004 7:25 pm
by AVATAr
just a comment

$PARAM=array_merge($_GET,_POST);

is the same as

$_REQUEST

Posted: Fri Nov 26, 2004 12:05 pm
by nyk
THANX!
Ok, a partial solution to the above problem seem to be this:
viewtopic.php?p=145133#145133