$uname = "another.12345";
$pin = "12345678";
$uploaddir = "uploads/";
$uploaddir = '/var/www/uploads/';
$max_size = 102400;
# do we want debug ?
$debug=1;
# do we want to use HTTPS for a secure connection?
$secure=1;
# $pfile contains the name of this script
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
#
if ($debug)
{
if (! file_exists("/tmp" )) { mkdir("/tmp", 0777); }
$myFile = "/tmp/" . $pfile . ".log";
$fh_debug = fopen($myFile, 'a') or die("can't open file");
fwrite($fh_debug, "\n\n" . $pfile . "\n". date("j F Y G:i:s") . "\n");
@chmod($myFile,0666);
}
############################################################
# Function definitions
############################################################
function http_post($vars)
{
global $debug, $fh_debug, $secure;
if($secure)
{
$urlencoded = "";
while (list($key, $value) = each($vars))
{
$urlencoded.= urlencode($key)."=".$value."&";
}
$urlencoded = substr($urlencoded, 0, -1);
if ($debug) {fwrite($fh_debug, "\nFirst 100 chars of URLENCODED=" . substr($urlencoded,0,100) . "\n");}
$url = "https://www.csoft.co.uk/webservices/http/sendsms";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 5s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlencoded); // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch);
return $result;
}
else {
$server1="www.csoft.co.uk";
$server2="www2.csoft.co.uk";
$port=80;
if ($debug) {fwrite($fh_debug, "PORT=" . $port . " SERVER=" . $server1 . "\n");}
# note that the sendsms web service is actually the same as the sendmms service...
$url= "/webservices/http/sendsms" ;
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)";
#
$urlencoded = "";
while (list($key, $value) = each($vars))
{
$urlencoded.= urlencode($key)."=".$value."&";
}
$urlencoded = substr($urlencoded, 0, -1);
if ($debug) {fwrite($fh_debug, "\nFirst 100 chars of URLENCODED=" . substr($urlencoded,0,100) . "\n");}
$content_length = strlen($urlencoded);
$headers = "POST $url HTTP/1.1\n";
$headers .= "Accept: */*\n";
$headers .= "Accept-Langauge: en-au\n";
$headers .= "Content-Type: application/x-www-form-urlencoded\n";
$headers .= "User-Agent: $user_agent\n";
$headers .= "Host: $server\n";
$headers .= "Connection: close\n";
$headers .= "Cache-Control: no-cache\n";
$headers .= "Content-Length: $content_length\n\n";
if ($debug) { fwrite($fh_debug, "\nHEADERS=" . $headers . "\n"); }
# attempt to open connection to server - with failover
$fp = @fsockopen($server1, $port, $errno, $errstr,5);
if ($fp)
{
$report= "server1 opened OK\n";
if ($debug) {fwrite($fh_debug, $report . "\n");}
}
else
{
$report= "server1 failed, trying server2\n";
if ($debug) {fwrite($fh_debug, $report . "\n");}
$fp = @fsockopen($server2, $port, $errno, $errstr,10);
if (!$fp)
{
$report= "server2 failed as well\n";
if ($debug) {fwrite($fh_debug, $report . "\n");}
return false;
}
else
{
$report= "server2 openened OK\n";
if ($debug) {fwrite($fh_debug, $report . "\n");}
}
}
fputs($fp, $headers);
fputs($fp, $urlencoded);
$ret = "";
while (!feof($fp))
{
$ret.=fgets($fp, 1024);
}
fclose($fp);
return $ret;
}
}
##############################
function ascii_convert($text)
{
$text = str_replace(' ', '___SPACE___', $text);
$text = urlencode($text);
$text = str_replace('___SPACE___', '%20', $text);
return $text;
}
############################################################
# generate the HTML - dependent on parameters passed
echo "
echo "";
echo "Software version dated 2008-05-28
";
$ToDo=$_REQUEST['ToDo'];
if ($ToDo == "")
{
if ($debug) { fwrite($fh_debug, "ToDo=" . $ToDo . "\n"); }
echo "Please choose an option from the list below:
";
echo "
echo "
echo "
";
}
elseif ($ToDo == "sms")
{
if ($debug) { fwrite($fh_debug, "ToDo=" . $ToDo . "\n"); }
echo "Please fill in the form below to send your message:
";
echo "
";
}
elseif ($ToDo == "sendsms")
{
if ($debug) { fwrite($fh_debug, "ToDo=" . $ToDo . "\n"); }
$message=$_REQUEST['message'];
$phone=$_REQUEST['phone'];
$message = stripslashes($message);
$message = ascii_convert($message);
if ($debug) { fwrite($fh_debug,"MESSAGE=" . $message . "\n");}
$sending = http_post(array("Username" => $uname, "PIN" => $pin, "SendTo" => $phone, "Message" => $message));
if ($debug) { fwrite($fh_debug, "SENDING=" .$sending . "\n");}
echo "Please choose an option from the list below:
";
echo "
echo "
echo "
";
}
elseif ($ToDo == "mms")
{
if ($debug) { fwrite($fh_debug, "ToDo=" . $ToDo . "\n"); }
echo "Please fill in the form below to send your message:
";
echo "
1 comments:
i get the error:
Fatal error: Call to undefined function curl_init() in C:\wamp\www\Binary\index.php on line 97
Post a Comment