By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

Login to a forum using php and curl

P: 10
I want to creat a weblogin client using php to login to this forum or someother.
but i am gating with the page that u have to login befor precede.
I am new to curl so cannot figure out where the problem is.


[PHP]
<?php
$usrname="xxxxxx";
$password="xxxxxxx";
$loginURL="http://www.thescripts.com/forum/login.php?do=showlogin";
$reffer="http://www.thescripts.com/forum/usercp.php?";
$cookiepath="/tmp/cookielog";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath);
curl_setopt($ch, CURLOPT_URL,$loginURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'vb_login_usern ame='.$usrname.'&vb_login_password='.$password);
ob_start();
curl_exec($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
curl_setopt($ch, CURLOPT_URL,$reffer);
$result = curl_exec ($ch);
print $result;
curl_exec($ch);
curl_close ($ch);
?>

[/PHP]
May 23 '07 #1
Share this Question
Share on Google+
8 Replies


pbmods
Expert 5K+
P: 5,821
Could you be more specific with what you're trying to accomplish here? Are you creating an auto-login script for your own personal use, or is this something you want to eventually put on a publicly-accessible website?
May 23 '07 #2

Motoma
Expert 2.5K+
P: 3,235
The biggest problem you have here is that you are not collecting and setting the user COOKIES for the site you are trying to connect to.
May 23 '07 #3

P: 10
This manily for my Learning Perpose i mentioned early that iam new in curl and php also oviously for my personal use not for any public use.
yes iam collection cookies by curl cookiejar option and store the cookies in /tmp .That is what i understand to use curl with cookies , i donot have any detailed idea.
May 23 '07 #4

Motoma
Expert 2.5K+
P: 3,235
Take a look at the form variables that are being sent to the login page. There are a few more than the ones you are POSTing.
May 23 '07 #5

P: 10
i have no idea how to post those hidden fields coz they may have certain value embeded and also they have md5hasing which php have a function of md5 but how to use those .
May 23 '07 #6

Motoma
Expert 2.5K+
P: 3,235
i have no idea how to post those hidden fields coz they may have certain value embeded and also they have md5hasing which php have a function of md5 but how to use those .
The chore of your project will be figuring these things out, watching (with Wireshark perhaps) what is getting POSTed and emulating that in your application.
MD5 is easy, just call it:

Expand|Select|Wrap|Line Numbers
  1. $pass = "dumb passphrase";
  2. $md5pass = md5($pass);
  3.  
May 23 '07 #7

P: 10
how to find out what is gating posted
May 25 '07 #8

Motoma
Expert 2.5K+
P: 3,235
how to find out what is gating posted
Wireshark is my favorite tool, but you could always use Fiddler. Fiddler is a bit more straightforward, and, it is designed with HTTP in mind.
May 25 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.