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("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 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.