curl login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deldadeh
Forum Newbie
Posts: 5
Joined: Sat Nov 21, 2009 1:22 pm

curl login

Post by deldadeh »

Hi i want to login a website with curl
and this is code
why it doesn't make any output and there is no result.

Code: Select all

 
$id =""; // my username
$password =""; // my pass
$secfrdcodedvar =""; // some value i get from the page
$frm-id=""; // some value i get from the page
$url=""; // address of <form> tag in action parameter
 
$POSTFIELDS = 'data[username]='.$id.'&data[password]='.$password.'&secfrdcodedvar='.$secfrdcodedvar.'&frm-id='.$frmid;
 
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url);
 
curl_setopt ($ch, CURLOPT_POST, true);
 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $POSTFIELDS );
 
curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
 
echo curl_exec ($ch);
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: curl login

Post by josh »

Turn on error reporting
deldadeh
Forum Newbie
Posts: 5
Joined: Sat Nov 21, 2009 1:22 pm

Re: curl login

Post by deldadeh »

josh wrote:Turn on error reporting
i turned it on but there is no error.
also i user header parameter, and sent me the successfull header, but i need the full page not just the header.
thanks
deldadeh
Forum Newbie
Posts: 5
Joined: Sat Nov 21, 2009 1:22 pm

Re: curl login

Post by deldadeh »

i mean this

the returned string is this
HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Sun, 22 Nov 2009 18:11:01 GMT Server: Apache/2.2.11 (Debian) X-Powered-By: Cloob Framework/1.0.1 Set-Cookie: PHPSESSID=54e51bd64e40e6bf3541345ee-895609; path=/; HttpOnly Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=54e51bd64e40e6bf3541345ee-895609; path=/ Set-Cookie: m_id=1258913462_7980061; expires=Thu, 08-Feb-2018 18:11:02 GMT; path=/ Location: /profile/main/home/username/systemuser Content-Length: 0 Connection: close Content-Type: text/html
i got from this header returned that it logined successfully. and now i want the complete page content.
and i use changed code to this:

Code: Select all

 
$ch = curl_init() or die( curl_error() );
 
curl_setopt($ch, CURLOPT_URL, $url);
 
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13');
 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $POSTFIELDS );
 
curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
 
curl_exec ($ch);
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: curl login

Post by josh »

Follow the http header redirect
deldadeh
Forum Newbie
Posts: 5
Joined: Sat Nov 21, 2009 1:22 pm

Re: curl login

Post by deldadeh »

josh wrote:Follow the http header redirect
how?
please help me.
explain more...
:drunk:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: curl login

Post by josh »

deldadeh
Forum Newbie
Posts: 5
Joined: Sat Nov 21, 2009 1:22 pm

Re: curl login

Post by deldadeh »


hi thanks
but this error occurs.
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/mysite/public_html/curl/curl.php on line 58

and there is another question,
how can i save the output page into a file?
and save in my host
thanks
Post Reply