-
Notifications
You must be signed in to change notification settings - Fork 93
Extended Functions for Data Source Development V3
There are 4 principle functions available to the caller ID sources.
They are:
-
SearchURL Returns the first matched element in a URL. Combines the functionality of preg_match and get_url_contents into one file. Will return FALSE if no match was found. Otherwise will return result AND will pass-by-reference on $match
-
ExtractMatch Extract the CID from a preg_match'd array (also works with returned data from function SearchURL)
-
get_url_contents Returns a string containing the contents of url specified by url and other optional parameters.
-
sys_get_temp_dir Returns the system defined temporary location for files
_SearchURL
_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 = $this->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 = $this->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($this->sys_get_temp_dir(), "CURLCOOKIE");
// Load the results page once to get some cookies set.
// The first result will fail, but the cookie file will be populated
$result = $this->get_url_contents($url,$post_data,$referrer,$cookie_file);
// Load the results page again, now that our cookie file has valid cookies
$result = $this->get_url_contents($url,$post_data,$referrer,$cookie_file);
// Delete the temporary cookie file, since we no longer need it
@unlink($cookie_file);