I'm building an application for my employer which is supposed to log into an online service, search for some vehicle info using license plate number and return this info to the script. The problem I'm having is that I am able to log in to the online service and return the "member's area", but when I try to search for the vehicle info using the form in said member's area, the data returned is just the same as before I posted the search form. The form's action seems to be the same as the uri I'm entering when logged in.
My file looks like this:
Code: Select all
<?php
//====================================================//
// Id: index.php //
// Date: 05.04.10 //
// Desc: File to connect to nbk.no using cURL //
// Auth: author //
//====================================================//
// Get functions.php //
require_once('functions.php');
// Get 1st redirect url to use for login url //
$url = 'http://nbk2.autodata.no';
$redir_1 = curl_extract($url);
$url_2 = $redir_1['url'];
// Attempt to login using $url_2 //
$data_2 = array('username' => urlencode('user'), 'password' => urlencode('pass'));
$redir_2 = curl_extract($url_2,true,$data_2);
$url_3 = $redir_2['url'];
// Attempt to search for vehicle when logged in //
$license = $_GET['plate'];
empty($license) == true ? $license = 'dummypl8' : $license = $license;
$data_3 = array(
'tp_articlesearch$search_vehicle_criterion' => '0',
'tp_articlesearch$input_search_single' => urlencode($license),
'tp_articlesearch$btn_search_single' => ''
);
$action_raw = curl_extract($url_3,false,'',true);
$action = extract_unit($action_raw,'<form name="Main" method="post" action="','" id="Main">');
$action = 'http://nbk2.autodata.no/' . html_entity_decode($action);
$content = curl_extract($action,true,$data_3,true);
echo $content;
?>
Code: Select all
<?php
$action_raw = curl_extract($url_3,false,'',true);
echo $action_raw;
?>
Does anyone have any clue why this is, and how it can be fixed?
My functions.php file looks like this btw
Code: Select all
<?php
//====================================================//
// Id: functions.php //
// Date: 05.04.10 //
// Desc: Misc cURL fuctions //
// Auth: Rune S. Lien //
//====================================================//
//===== Extract url or response from cURL-session ====//
function curl_extract( $url, $post = false, $postData = '', $returnContent = false ){
$agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; nb-NO; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => true, // return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => $agent, // user agent
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
if($returnContent == true){
$options[CURLOPT_HEADER] = false;
}
if($post == true){
$options[CURLOPT_POST] = true; // Enable post headers
$options[CURLOPT_POSTFIELDS] = $postData; // Set post data
}
$ch = curl_init( $url ); // Initialize cURL session
curl_setopt_array( $options ); // Set cURL options
$content = curl_exec( $ch ); // Get cURL response [Returned]
$errno = curl_errno( $ch ); // Get cURL error number
$errmsg = curl_error( $ch ); // Get cURL error message
$header = curl_getinfo( $ch ); // Get cURL-info [Returned]
curl_close( $ch );
return $returnContent == false ? $header : $content; // Return header or content
}
//================= EOF curl_extract() ===============//
//====== Extract a sub-string from given content =====//
function extract_unit($string, $start, $end){
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}
//================= EOF extract_unit() ===============//
?>