Re: [PHP] Bind IP with fsockopen



On 4/11/07, chris@xxxxxxxxxxxx <chris@xxxxxxxxxxxx> wrote:
Thanks how would I handle the fgets line..
http://www.php.net/socket_read
If I echo $sock I get resource ID #4 rather then the responce from
the other computer. Before on my original script I returned the responce
using

fputs($fs, "$domain\r\n"); // send query
$line = fgets($fs, 1024); // store reply
echo $line; // output reply

so far I have..

<?php

$domain = 'internet.co.uk';

$sourceip = 'xx.xx.xx.xx'; // ip you want to bind to
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'dac.nic.uk', 2043);
// Write
$request = "$domain\r\n\n"; // send request
socket_write($sock, $request); // store reply

echo $sock; //output reply??

socket_close($sock); // Close

?>


----- Original Message -----
From: "Richard Lynch" <ceo@xxxxxxxxx>
To: <chris@xxxxxxxxxxxx>
Sent: Wednesday, April 11, 2007 1:19 AM
Subject: Re: [PHP] Bind IP with fsockopen


>
>
> fputs adds a newline, and you've got \r\n already, so your total
> output in the original is \r\n\n
>
> In the socket_bind one, you've got none of the \r\n stuff at all, much
> less \r\n\n
>
> On Tue, April 10, 2007 5:56 pm, chris@xxxxxxxxxxxx wrote:
>> Im having trouble converting this snippet to use the bind_socket
>> function.
>>
>> my original code is..
>>
>> <?
>> $domain = 'internet.co.uk';
>>
>> $fs = fsockopen('dac.nic.uk', 2043, $errno, $errstr, 60);
>> if (!$fs) {
>> fclose($fs);
>> } else {
>>
>> fputs($fs, "$domain\r\n");
>> $line = fgets($fs, 1024);
>> echo $line;
>> }
>> ?>
>>
>> I think im getting stuck on the fputs bit.. I have this which does not
>> work..
>>
>> <?php
>>
>> $domain = 'internet.co.uk';
>>
>> $sourceip = 'xx.xx.xx.xx'; // ip you want to bind to
>> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
>> socket_bind($sock, $sourceip);
>> socket_connect($sock, 'dac.nic.uk', 2043);
>> // Write
>> $request = "$domain\r\n";
>> socket_write($sock, $request);
>> //Read reply
>> // Close
>> socket_close($sock);
>> ?>
>>
>> Thanks
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>
>

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


.



Relevant Pages

  • Re: [PHP] IPv6 validation
    ... echo "$ip is not a valid IP"; ... PHP General Mailing List ... I installed php5 on my local dev box years ago. ... my company to upgrade and fix code that busted in the transition. ...
    (php.general)
  • Re: [PHP] mysql if empty
    ... echo "No result found"; ... Centro de Telemática | Administrador ... PHP General Mailing List ... To unsubscribe, visit: http://www.php.net/unsub.php ...
    (php.general)
  • mysql if empty
    ... If I search for something in mysql that returns an empty result I cant get it to return ... echo "No result found"; ... PHP General Mailing List ...
    (php.general)
  • Re: [PHP] mysql if empty
    ... This doesn't meant that the variable holding the reference to the result set is itself empty, but that you will fail to fetch any results from it. ... echo "No result found"; ... PHP General Mailing List ... To unsubscribe, visit: http://www.php.net/unsub.php ...
    (php.general)
  • Re: [PHP] IPv6 validation
    ... an IPv6 address. ... echo "$ip is not a valid IP"; ... PHP General Mailing List ... To unsubscribe, visit: http://www.php.net/unsub.php ...
    (php.general)