Sending SMS Thru HTTP - Sending the Request with Sockets
(Page 23 of 36 )
CURL functions depend on an external library and PHP must have been compiled with the --with-curl flag. So while CURL is very flexible and useful, it may not be available with your PHP installation. If this is the case, you can still communicate with the SMS gateway using sockets.<?php//First prepare the info that relates to the connection$host = "tm4b.com";$script = "/client/api/send.php";$request_length = strlen($request);$method = "POST"; // must be POST if sending multiple messagesif ($method == "GET") { $script .= "?$request";}//Now comes the header which we are going to post. $header = "$method $script HTTP/1.1\r\n";$header .= "Host: $host\r\n";$header .= "Content-Type: application/x-www-form-urlencoded\r\n";$header .= "Content-Length: $request_length\r\n";$header .= "Connection: close\r\n\r\n";$header .= "$request\r\n";//Now we open up the connection$socket = @fsockopen($host, 80, $errno, $errstr); if ($socket) //if its open, then...{ fputs($socket, $header); // send the details over while(!feof($socket)) { $output[] = fgets($socket); //get the results } fclose($socket); } /* the message id's will be kept in one of the $output valuesprint "<pre>";print_r($output);print "</pre>";*/
First we layout the information we'll need to send our SMS and use it construct the HTTP header. A socket connection is established to our gateway using fsockopen. Information is sent and received in the same manner PHP would read and write to a file. After our transfer is complete we close the socket using fclose.
Next: Conclusion >>
More Miscellaneous Articles
More By Codewalkers
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|