Running a script from an other server through php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nyk
Forum Newbie
Posts: 13
Joined: Mon Nov 22, 2004 8:07 pm
Location: Berne, Switzerland
Contact:

Running a script from an other server through php

Post 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?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

fsockopen()

ini_set('user_agent', 'msie 5.0 etc...');
nyk
Forum Newbie
Posts: 13
Joined: Mon Nov 22, 2004 8:07 pm
Location: Berne, Switzerland
Contact:

Post 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!!!!!
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

just a comment

$PARAM=array_merge($_GET,_POST);

is the same as

$_REQUEST
nyk
Forum Newbie
Posts: 13
Joined: Mon Nov 22, 2004 8:07 pm
Location: Berne, Switzerland
Contact:

Post by nyk »

THANX!
Ok, a partial solution to the above problem seem to be this:
viewtopic.php?p=145133#145133
Post Reply