[Tutorial] Curl Login

This is a discussion on [Tutorial] Curl Login within the PHP forums, part of the Program Your Site category; ill be making a detailed regex tutorial...


Go Back   Scriptasy > Program Your Site > PHP
111 Online Register Projects Products Members List Calendar Today's Posts

Reply

 

LinkBack (19) Thread Tools Display Modes
  #21 (permalink)  
Old 01-21-2008, 10:22 AM
[Administrator]
 
Join Date: May 2007
Posts: 382
ill be making a detailed regex tutorial
Reply With Quote
  #22 (permalink)  
Old 03-29-2008, 07:27 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Using Curl For Cj

Hi Chad!

i'd like to know if you can help me. I'm trying to login Commission Junction - A Global Leader in Affiliate Marketing, Online Advertising and Search Engine Marketing but it's so hard for me.

I've tried with this url and this other one:

https://members.cj.com/member/publisher/home.do that is the login page

The 2 both url have different POST data i have to send, these POST's data are:
Code:
uname=REMOVED&pw=REMOVED&submit.x=19&submit.y=5
and
Code:
uname=REMOVED&pw=REMOVED&nextpage=&go=Go
respectevely.

Well, I've seen the first POST data i wrote change temporaly. Where you see the "19" and the "5" sometimes change. But the second POST data i wrote to you is the same always, you just need to write your id and pass.

But anyway, i think the problem is for the COOKIE. When i intercept the data using ACHILLES i can see something like:

Code:
Cookie: cjlocale=en_US; __utma=xxxxxxxxx.xxxxxxxxxxx.xxxxxxxxxxxxx.xxxxxxxxxxxx.xxxxxxx.xxx; __utmz=xxxxxxxxx.xxxxxxxxxxx.xx.x.utmccn=(referral)|utmcsr=uk.cj.com|utmcct=/|utmcmd=referral; __utmb=xxxxxxxxx; CONTID=xxxxxxx; __utmc=xxxxxxxxxx
I've changed the cookie values because i'm not sure if i could share this data

This data changes temporaly too and sometimes include the JSESSIONID code

I've tested a lot of combination of these cookies with all the CURL's functions and i can't login. Always the browser shows me the CJ login form again.

As information, yesterday, i did the perfect code and it has worked fine for me, but that was just a newbie lucky because when i lost the session i wasn't be ables to login again. I've just changed the session and cookie values but it doesn't work.

Now, as i said, i've tested a lot of combination, even passing the utm... values i wrote above by adding the CURLOPT_COOKIE function and it doesnt't work neither.

Can u help me by saying to me what i have to write in your code to make it works perfectly for cj.com???

Thank you in advance.

Reinaldo.

P.D.: Sorry for my english, i know it isn't very good.
Reply With Quote
  #23 (permalink)  
Old 03-30-2008, 05:32 PM
[Administrator]
 
Join Date: May 2007
Posts: 382
well, if there is a session value that is changing and its a post field on the page what you will want to do is use, preg_match to grab the values on the page then add them to your post string. Hope this helps.
Reply With Quote
  #24 (permalink)  
Old 03-30-2008, 11:02 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Quote:
Originally Posted by Chad View Post
well, if there is a session value that is changing and its a post field on the page what you will want to do is use, preg_match to grab the values on the page then add them to your post string. Hope this helps.
I'm not sure if i am understanding you. Well, you're right, i can use preg_match to grab the POST fields data, i don't know how to do that but that's not the problem.

The postfileds data i have to send in cj.com changes, but that's ok no problem and even the postfield data that i have to send to https://members.cj.com/member/login (that is basically the same login page) don't changes, this is better than the first one.

The problem is another one, i think it is about COOKIES. When i try your code and all the codes i've been testing i can see the following line in the cookie file grabbed by COOKIEJAR function:

members.cj.com FALSE / FALSE 0 JSESSIONID xxxxxxxxxxx

I think this line means that CURL is logging in satisfactorily because the this cookie shows me a JSESSIONID value. When the code fails a FALSE value is shown instead the JSESSIONID value.

Well, even showing the JSESSIONID value, CURL can't show me the page that i'm looking for inside the login form.

I think this problem is for COOKIE values, when i intercept the data, i can see my browser is sending to CJ server utma, utmc, utmz, utmb values and even sometimes the JSESSIONID as a cookie value.

Intercepting the data a lot of times, i can see this utmX values appear ramdomly. I mean, sometimes appears the utmb cookie and some other times not and it is the same for utmc, JSESSIONID and a cookie named cjuMember.

This values appears ramdomly even in the same session. I'm trying to pass this __utmX values by using the CURLOPT_COOKIE function but it still not working.

Do you know about the utmX cookie values and how can i pass this data to the session created by CURL???

Thank you in advance.

Reinaldo.
Reply With Quote
  #25 (permalink)  
Old 05-27-2008, 10:40 AM
Junior Member
 
Join Date: May 2008
Posts: 1
hmm I am also just starting to loggin with cookies/curl.

I had a little bit similar problem as you had above.
I needed to log in monsterboard.nl ( ssl hiring ).

I did the following thing and it worked.

step 1:

Quote:
$LOGINURL = " Login url "
";
$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_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
$result = curl_exec ($ch);
curl_close ($ch);

step 2 : cookie is written

$LOGINURL = " Now do live http headers and get the same post sent page";
$POSTFIELDS = '$post data';
$reffer = "Same url as LOGIN url";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
$result = curl_exec ($ch);
curl_close ($ch);



This should do the job.
Reply With Quote
  #26 (permalink)  
Old 09-02-2008, 12:17 AM
Junior Member
 
Join Date: Sep 2008
Posts: 1
Sorry resurrect the topic,
More here the page is blank
when I try, Reason?
Reply With Quote
  #27 (permalink)  
Old 01-14-2009, 09:12 AM
Junior Member
 
Join Date: Jan 2009
Posts: 2
Hello, Chad, I have been playing with your script here, but still haven't gotten it to work. Some really useful tools thought, like the liveHTTPheaders thing.

I originally started this little project just trying to use command line curl and putting it in a shell script:

curl -d "login information password etc" http://url/index.php

using live headers was a big help because it gave me the correct info to send as data (all kinds of stuff...). Finally I was logged in, but only to the redirect page ( please wait while we redirect you etc ). Couldn't seem to get past that.

Interesting, when I use your script, with the same data, I don't get logged in, but get a page saying "your are unauthorized to do that". Maybe you have some input on all of this.

One general question though:

In the second part of the script, curl_grab_page(), am I correct in assuming that it is strictly relying on cookies to allow privileged access? I am wondering this, because I wondering if the site that I am trying to grab the page on is using some means other than cookies to "remember me" (after checking the "remember me" box on logging in).

I was wondering this because I have tried capturing the cookies during a login and explicitly sending them when invoking curl, but that hasn't worked.

Another general question is, in your script it appears curl is executed twice, once for the login, and once to grab the page. Does the server see this as all the same session, or does it get broken up in two sessions?

Thanks for anything you can help me with here.

Allasso

Last edited by allasso; 01-14-2009 at 09:20 AM.
Reply With Quote
  #28 (permalink)  
Old 02-05-2009, 06:32 PM
Junior Member
 
Join Date: Feb 2009
Posts: 1
Video is too quite, code sucked, try this:

Quote:

function fetch($url,$post=false,$cookie=false,$timeout=30) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
}
if ($post) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, TRUE);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//curl_setopt($ch, CURLOPT_HEADER, TRUE); //debug
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$cookie=tempnam('','');
$url='http://www.example.com/login.php';
$post='username=example&password=qwerty';
fetch($url,$post,$cookie);
$url='http://www.example.com/something/important.zip';
echo fetch($url,false,$cookie);
?>
I'm sure you get the idea.
Reply With Quote
  #29 (permalink)  
Old 02-06-2009, 05:31 AM
Junior Member
 
Join Date: Jan 2009
Posts: 2
Thanks, maybe when I have time I'll try it for academic's sake.

I did what I want with this in the shell:

curl -s -o /dev/null -b $cookiejar -c $cookiejar -d $login_data $site_url 2> /dev/null
curl -s -b $cookiejar -c $cookiejar $site_url/page_i_want

way simpler. You could use shell_exec() if you want to wrap it in PHP for some reason.
Reply With Quote
  #30 (permalink)  
Old 02-08-2009, 06:54 AM
Junior Member
 
Join Date: Feb 2009
Posts: 1
dfgsdfggsdcd

brazilian bikini video
big nipples
boob pics
boob job
brazilian bikini video
big nipples
boob pics
boob job
http://wis.dm/users/71386-brazilianbik brazilian bikini video
wis.dm - bignipples big nipples
wis.dm - boobpics boob pics
wis.dm - boobjob boob job
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://scriptasy.com/php_11/tutorial-curl-login_44.html

Posted By For Type Date
Can a website block the use of file_get_contents ? - PHWinfo This thread Refback 08-22-2008 01:13 AM
Can a website block the use of file_get_contents ? - comp.lang.php | Google Groups This thread Refback 04-26-2008 11:12 AM
Can a website block the use of file_get_contents ? - comp.lang.php | Google Groupes This thread Refback 04-23-2008 04:43 AM
Live website statistieken - Ulco.nl This thread Pingback 03-31-2008 11:37 AM
Can a website block the use of file_get_contents ? - comp.lang.php | Google Groups This thread Refback 03-31-2008 08:03 AM
Can a website block the use of file_get_contents ? - comp.lang.php | Google Groups This thread Refback 03-29-2008 03:21 AM
Can a website block the use of file_get_contents ? - Object Mix This thread Refback 03-29-2008 03:10 AM
Can a website block the use of file_get_contents ? - Usenet Forums This thread Refback 03-28-2008 10:45 AM
Web Link This thread Refback 09-05-2007 07:15 PM
amob005's bookmarks tagged with "php_curl_video_tutorial" on del.icio.us This thread Refback 08-12-2007 12:41 AM
digg / blizzedout / news / dugg This thread Refback 06-17-2007 02:14 AM
digg / beasttoast / news / submitted This thread Refback 06-02-2007 02:02 PM
YouTube - Curl Login Tutorial This thread Refback 05-31-2007 04:37 PM
Digg / Programming / Upcoming This thread Refback 05-31-2007 01:36 PM
Digg / Programming / Upcoming This thread Refback 05-31-2007 09:16 AM
Digg / News / Upcoming This thread Refback 05-30-2007 10:08 PM
Digg / News / Upcoming This thread Refback 05-30-2007 10:05 PM
Digg / News / Upcoming This thread Refback 05-30-2007 10:00 PM
Digg - [Tutorial] PHP Curl Login This thread Refback 05-30-2007 10:00 PM


All times are GMT -8. The time now is 10:28 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
scriptasy girl by HitmanN

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
W33