Re[2]: Bind IP with fsockopen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux