Page 1 of 1

PHP - Sending a packet

Posted: Tue Jun 28, 2005 5:20 pm
by genetix
Is there a way to send a PHP packet from one server(php code) to another website?

I need to send a message to a server and get a response using a packet. Is it possible in PHP?

Posted: Tue Jun 28, 2005 6:09 pm
by Burrito

Posted: Tue Jun 28, 2005 6:16 pm
by jadams
for more info, check this out: http://us4.php.net/manual/en/ref.curl.php

Posted: Tue Jun 28, 2005 7:19 pm
by genetix
whats an example of how I could send a packet to a server ip and get a response on a different server.

Like:

send_packet(22.22.22.22, 44.44.44.44, testresponse);
22.22.22.22 = server to send to
44... = server to receive to

Posted: Wed Jun 29, 2005 4:34 pm
by genetix
Any idea?

I'm not sure which part of curl to use. I have never had to use it before.

Posted: Wed Jun 29, 2005 4:41 pm
by Burrito
a sample of how I use cURL this is:

Code: Select all

$fields = "field_1=value1&field_2=value2";
$ref = "https://www.yourdomain.com";
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"; 
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://www.yourserver.com/your_page.php"); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_NOPROGRESS, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_REFERER, $ref); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($ch); 
curl_close($ch); 
// build an array of what is returned from the server...burrito
$return = explode(",",$buffer);
obviously, change that you will need to suit your needs. read cURL I suggest you do.

Posted: Tue Jul 19, 2005 9:18 pm
by genetix
What about using server();

Would that work aswell? I would prefer not having to install extra components. The php.net website says that you have to install the curl module.

Posted: Wed Jul 20, 2005 2:36 am
by onion2k
People are suggesting cURL because it's be far the best way to do HTTP comms in PHP. If you're happy doing things at a lower level with raw sockets, use fsockepen() ( http://uk.php.net/fsockopen ) to open a connection, the fwrite() to write something to it.

I doubt there's a way to specify the return IP address. It'd be rather a massive security issue.