Jump to content

Problem with cURL library


Holmes.Sherlock

Recommended Posts

Hi,

 

I've asked to automate the login process of the http://reboot.pro forum. The login form is available at http://reboot.pro/index.php?app=core&module=global&section=login. The HTML form shown below can be used to login to the forum:

 

 
<html>
<form action="http://reboot.pro/index.php?app=core&module=global&section=login&do=process" method="post" id='logon'>
  <input type='hidden' name='auth_key' value='880ea6a14ea49e853634fbdc5015a024' />    
  <input type='text' name='username' />
  <input type='password' name='password' />
  <input type='submit' value='Sign In' />
</form>
</html>

 

To simulate the login process from the PHP code, I've written the script:

<?php
//create array of data to be posted
$post_data['auth_key'] = '880ea6a14ea49e853634fbdc5015a024';
$post_data['username'] = 'testaccount';
$post_data['password'] = 'testaccount';

//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);
echo $post_string;

//create cURL connection
$curl_connection = curl_init('http://reboot.pro/index.php?app=core&module=global&section=login&do=process');

//set options
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);echo $result;

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);

//close the connection
curl_close($curl_connection);

?>

 

But, in effect, login process is not triggered but the forum homepage, i.e. which is presented to Guest users, appears. Can anubody plese help me in fixing this or point me out where am I doing wrong?

 

Note: I'm using EasyPHP (latest stable version) with cURL extension enabled.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/244311-problem-with-curl-library/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.