SMS API: PHP Code |
|
OverviewEach of the following PHP functions communicate with our server, make an HTTP request and then returns our response. Once the most suitable function has been installed, sending SMS (for example) can be sent in as little as one line of code. To use any of these functions:
CURLThe following function uses the CURL library.
<?
function tm4b($request)
{
if(!extension_loaded('curl')) $response = "Function requires CURL.";
else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.tm4b.com/client/api/http.php"; curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch);
}
return $response;
}
?>
fsockopenThe following function uses fsockopen.
<?
function tm4b($request)
?>
{
if(!extension_loaded('sockets')) $response = "Function requires sockets.";
}
else {
$http_header = "POST /client/api/http.php HTTP/1.1\r\n";
}$http_header .= "Host: tm4b.com\r\n"; $http_header .= "User-Agent: HTTP/1.1\r\n"; $http_header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $http_header .= "Content-Length: ".strlen($request)."\r\n"; $http_header .= "Connection: close\r\n\r\n"; $http_header .= $request."\r\n"; $host = "ssl://tm4b.com"; $port = 443; $out = @fsockopen($host, $port, $errno, $errstr); if($out) {
fputs($out, $http_header);
}while(!feof($out)) $result[] = fgets($out); fclose($out); $response = $result[9]; return $response; file_get_contentsThe following function uses file_get_contents.
<?
function tm4b($request)
?>
{
return file_get_contents("https://www.tm4b.com/client/api/http.php?".$request);
} |
|