Page 1 of 1

make a phone call PHP script

Posted: Fri Feb 06, 2009 11:10 am
by piezomot
Hi, I am new to PHP. I was doing some research via goggle and was trying to built a script which would login into a free phone call web site (http://labs.jaduka.com) and then initiate a phone call. First script would login and then the phone number I want to call must be taken by this script from a simple txt file and inserted into the field (enter the number you wish to call)

I have created a file startacall.bat with the string makeacall.php (php is installed on my PC) and run it.

My question is how can I debug it? Again my PHP knowledge is limited may be someone can help me to "polish" it...

Thank you!

Code: Select all

<?php
 
/////////////////////////////////////////////////////////////////////////////////////////
// Do the login
/////////////////////////////////////////////////////////////////////////////////////////
 
function login($url_login,$url_referer,$postString){
   global $agent;
   global $cookie;
 
   $debug = false;                     // Set to 'true' for debug info
 
   $ch = curl_init();                  // Initialize a new session and return a CURL handle
   curl_setopt($ch,CURLOPT_USERAGENT,$agent);         // Impersonate browser
   e         // Fake the referer
   curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);         // File to save all internal cookies to when the connection closes
   curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);         // File containing the cookie data
   curl_setopt($ch,CURLOPT_URL,$url_login);         // Set the page to visit
   curl_setopt($ch,CURLOPT_POST,1);            // Prepare to perform an HTTP POST operation (obsolete?)
   curl_setopt($ch,CURLOPT_POSTFIELDS,$postString);      // Fill in the form and submit
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);         // Return a string containing the page
   curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);         // Dont check the certificate
   curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);         // Follow redirection
   $data = curl_exec($ch) or die(curl_error($ch));       // Execute the curl command
   curl_close($ch);                  // Close the session
 
   if($debug){
      // echo "<PRE>".htmlentities($data);         // View the returned page code
      echo nl2br($data);               // View the returned page
   }
}
 
//--------------------------------------------------------------------
// These are the details for the freecall web site.
$username = "";                        // my username
$password = "";                        // my password
$numbertocall = ""; // number to call   
$url_login = "http://labs.jaduka.com/dukaDial";   // Login page
$url_ref = "http://labs.jaduka.com";               // Site may check the referer, so fake it
$userFieldName = "username";                  // Viewed web page source to find this
$passwordFieldName = "password";                  // Viewed web page source to find this
 
$postString = $userFieldName."=".$username."&".$passwordFieldName."=".$password."&action=login";   // post string username and password
//--------------------------------------------------------------------
 
login($url_login,$url_referer,$postString);            // Log in jaduka.com
 
/////////////////////////////////////////////////////////////////////////////////////////
// Make a call
/////////////////////////////////////////////////////////////////////////////////////////
$numbertocall = "numbertocall.txt";
$numbertocallFieldName = "numbertocall";   // This must be the number to call
$postnumbertocall = $."=".$postnumbertocall."&action=makeacall";   // post string number to call
 
makeacall($url_login,$url_referer,$postnumbertocall);            // make a call
 
?>