Page 1 of 1

Help for php cURL Login

Posted: Wed Dec 19, 2012 5:33 pm
by iserge
Now I am trying to login to my account using PHP and CURL, but still I am not sure why is not working.

The page I'm trying to login to is: http://lardi-trans.com/index.jsp After the execution of the script, I get header of page.
Help to find error.
Thanks in advance!

Code: Select all

<?php
$url = "http://lardi-trans.com/log/index.jsp";
$referer = "http://lardi-trans.com/index.jsp";
$user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/20100101 Firefox/17.0";
$post = "action=/log/login.jsp&log=MYLOGIN&passwd=MYPASSWORD&enter=enter&onlog=%D0%92%D0%BE%D0%B9%D1%82%D0%B8";
$header [] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header [] = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3";
$header [] = "Accept-Encoding:gzip,deflate";
$header [] = "Accept-Language:en-US,en;q=0.5";
$user_cookie = "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url ); 
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, "identity");
curl_setopt($ch, CURLOPT_COOKIEFILE, $user_cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $user_cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$page = curl_exec($ch);
curl_close($ch);

echo $page;
?>

Re: Help for php cURL Login

Posted: Wed Dec 19, 2012 6:01 pm
by Christopher
Did you try:

Code: Select all

curl_setopt($ch, CURLOPT_HEADER, 0);

Re: Help for php cURL Login

Posted: Wed Dec 19, 2012 6:04 pm
by iserge
Yes. And i see blank page)

Re: Help for php cURL Login

Posted: Sun Dec 23, 2012 12:36 am
by Eric!
Your post string shouldn't contain the url query, just the fields. Are you sure you have all the fields including any hidden ones in the form? You could try using firefox and an extension like live http headers to view what is submitted during login.

Also, use this trick for debugging curl by putting the debug info stream into a file:

Code: Select all

$file = "debug.txt";
$fp=fopen($file,"w+");
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_STDERR,$fp);
That should give you a start.

Edit: Also you might need to set the referring url to the url that submits the form

Code: Select all

curl_setopt($handle, CURLOPT_REFERER, 'http://www.example.com/1');