Repository navigation
Extended Functions for Data Source Development V3
There are 4 principle functions available to the caller ID sources.
They are:
- get_url_contents Returns a string containing the contents of url specified by url and other optional parameters.
get_url_contents (string url, [array post_data], [string referrer], [string cookie_file], [string useragent]) Returns a string containing the contents of url specified by url and other optional parameters.
A string containing the full url of the page you would like to receive.
An array containing the data you would like to post. If not provided or set to false, no data will be posted.
A string containing the full url of the referring page. If not provided or set to false, no referrer will be used.
A string containing the full path to the file you will use to store cookie data. If not provided or set to false, cookies will not be used.
A string containing the user agent to masquerade as. If not provided or set to false, the default user agent is: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
// Set the url
$url = "http://www.google.com";
// Get the url
$result = get_url_contents($url);// Create the post array. The key is the form element's name, the value is the form element's value
$post_data = array(
"form_element_name_1" => "form_element_value_1",
"form_element_name_2" => "form_element_value_2",
"form_element_name_3" => "form_element_value_3"
);
// Set the url of the page the form data should be submitted to
$url = "http://www.maypage.com/form_proccessing_page";
// Post the form data and return the results
$result = get_url_contents($url, $post_data);// Set the referring page. In this case, it is the url of the page containing the form.
$referrer ="http://www.telekom.rs/WhitePages/SearchPage.asp";
// Set the url of the page that will be processing the posted data
$url="http://www.telekom.rs/WhitePages/ResultPage.asp";
// Set the data that will be posted
$post_data = array(
'Telefon'=>$phone_number,
'Ulica'=>'',
'MG'=>$area_code,
'Ime'=>'',
'Broj'=>'',
'Mesto'=>'',
'Prezime'=>'',
'submit.x'=>'58',
'submit.y'=>'10'
);
// Create a temporary path for a cookie file in the /tmp directory
$cookie_file = tempnam("/tmp", "CURLCOOKIE");
// Load the results page once to get some cookies set.
// The first result will fail, but the cookie file will be populated
$result = get_url_contents($url,$post_data,$referrer,$cookie_file);
// Load the results page again, now that our cookie file has valid cookies
$result = get_url_contents($url,$post_data,$referrer,$cookie_file);
// Delete the temporary cookie file, since we no longer need it
@unlink($cookie_file);