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?
PHP - Sending a packet
Moderator: General Moderators
for more info, check this out: http://us4.php.net/manual/en/ref.curl.php
a sample of how I use cURL this is:
obviously, change that you will need to suit your needs. read cURL I suggest you do.
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);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.
I doubt there's a way to specify the return IP address. It'd be rather a massive security issue.