Re[2]: [PHP] Bind IP with fsockopen

From: Date: Sun, 08 Apr 2007 04:46:28 +0000
Subject: Re[2]: [PHP] Bind IP with fsockopen
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-252237@lists.php.net to get a copy of this message
Hi, TR> You will have to do it using the socket api something like this but TR> with error checking: TR> <?php TR> $sourceip = '192.168.1.1'; // ip you want to bind to TR> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); TR> socket_bind($sock, $sourceip); TR> socket_connect($sock, 'example.com', 2043); TR> // Write TR> $request = 'GET / HTTP/1.1'."\r\n".'Host: TR> example.com'."\r\n\r\n"; TR> socket_write($sock, $request); TR> //Read reply TR> // Close TR> socket_close($sock); Another option using streams (php5): <?php $opts = array( 'socket'=>array( 'bindto'=>'192.168.1.1:0' //any port will do ) ); $context = stream_context_create($opts); $html = file_get_contents('http://example.com:2043', false, $context); -- regards, Tom

« previous php.general (#252237) next »