OK here is a piece of code I've been working on that actually logs you in and returns what ever Curl sees except i have no idea how to make Curl function correctly with websites that require cookie authentication correctly, can anyone help? =/
Curl login authentication cookie issues
<?php
//create array of data to be posted
$post_data['username_here'] = "username";
$post_data['password_here'] = "password";
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
$post_string = "dest=%2".$post_string ."&submit=next";
//i.e. ?dest=%2F&username=username_here&password=password_here&submit=next
//create cURL connection
$curl_connection = curl_init("https://my.netspace.net.au/logincheck");
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); //set time untill cURL times out
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); // set HTTP User Agent
curl_setopt($curl_connection, CURLOPT_HEADER,1);
curl_setopt($curl_connection, CURLOPT_POST, 1);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);//set data to be posted
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); // follow redirection if any...
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); //determin if to continue processing code if SSL certificate is verifyed or not...
//cookie code ive found that dont seem to work...
/*curl_setopt($curl_connection, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIE, "cookies.txt");
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($curl_connection, CURLOPT_COOKIESESSION, true); //return cookies that cURL collects*/
//perform our request (execute request)
$result = curl_exec($curl_connection);
curl_close();
echo $result;
?>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.