Orio Posted August 26, 2006 Share Posted August 26, 2006 *SOLVED*Hi :)I am trying to learn how to use cURL, and I find it very difficult.So far what I am trying to do is log into some site, and then display the source of the the main page after the log in (it looks diffrent before and after you log in).Here it is:[code]<?php$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");curl_setopt($ch, CURLOPT_URL,"http://www.domain.com/login.php");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, "submit=TRUE&email=".urlencode("me@gmail.com")."&password=".urlencode("pass"));curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_exec ($ch);curl_close ($ch);unset($ch);$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");curl_setopt($ch, CURLOPT_URL,"http://www.domain.com/");curl_setopt($ch, CURLOPT_HEADER, TRUE); $buf2 = curl_exec ($ch);curl_close ($ch);echo "<PRE>".htmlentities($buf2)."</PRE>";?>[/code]But the output I get is weird, I think I am getting only the headers![code]HTTP/1.1 302 FoundCache-Control: no-cache, must-revalidatePragma: no-cacheP3P: CP="NOI IVDa OUR NOR STA"Set-Cookie: sessid13-suid=221372; expires=Sat, 02 Sep 2006 16:00:22 GMT; path=/; domain=.example.comSet-Cookie: sessid13-ssid=99ceb6d6e6e6772c02db8bd3ddd1f69a; expires=Sat, 02 Sep 2006 16:00:22 GMT; path=/; domain=.example.comSet-Cookie: session=deleted; expires=Fri, 26 Aug 2005 16:00:21 GMTlocation: index.php?session=Content-type: text/htmlContent-Length: 0Date: Sat, 26 Aug 2006 16:00:22 GMTServer: GHOST[/code]What's wrong? ???**It's important to mention this site uses cookies for the login system- if I delete their cookies I'll be out.**Also- if I change the password to a wrong password, I get the source of the "please log in!" page. It's the main page I cant see :(Help will be greatly appreciated :)Thanks,Orio.EDIT- yay! I found it! I just added "curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);", and removed "curl_setopt($ch, CURLOPT_HEADER, TRUE);" (I thought "CURLOPT_HEADER" us doing what "FOLLOWLOCATION" is doing :)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.