Re: Bind IP with fsockopen
| From: | Tom Rogers | Date: | Sun, 08 Apr 2007 03:06:34 +0000 |
| Subject: | Re: Bind IP with fsockopen | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252232@lists.php.net to get a copy of this message | ||
Hi,
Sunday, April 8, 2007, 6:51:46 AM, you wrote:
cac> Hi is it possible to socket_bind with fsockopen? im using this with all my scripts...
cac> $fs = fsockopen('example.com', 2043, $errno, $errstr, 60);
cac> if (!$fs) {
cac> fclose($fs);
cac> and I need the remote conection to see me as one of my other IP's
cac> Ive read through socket_bind
cac> http://uk.php.net/manual/en/function.socket-bind.php
cac> but cant see how to use it with my above code
cac> Thanks
You will have to do it using the socket api something like this but
with error checking:
<?php
$sourceip = '192.168.1.1'; // ip you want to bind to
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'example.com', 2043);
// Write
$request = 'GET / HTTP/1.1'."\r\n".'Host:
example.com'."\r\n\r\n";
socket_write($sock, $request);
//Read reply
// Close
socket_close($sock);
?>
--
regards,
Tom