Jump to content

Learning cURL... *SOLVED!*


Orio

Recommended Posts

*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("[email protected]")."&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 Found
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
P3P: CP="NOI IVDa OUR NOR STA"
Set-Cookie: sessid13-suid=221372; expires=Sat, 02 Sep 2006 16:00:22 GMT; path=/; domain=.example.com
Set-Cookie: sessid13-ssid=99ceb6d6e6e6772c02db8bd3ddd1f69a; expires=Sat, 02 Sep 2006 16:00:22 GMT; path=/; domain=.example.com
Set-Cookie: session=deleted; expires=Fri, 26 Aug 2005 16:00:21 GMT
location: index.php?session=
Content-type: text/html
Content-Length: 0
Date: Sat, 26 Aug 2006 16:00:22 GMT
Server: 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 :))
Link to comment
https://forums.phpfreaks.com/topic/18728-learning-curl-solved/
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.