Forum Moderators: coopster

Message Too Old, No Replies

PHP cURL help needed

PHP Curl Library cookies and sessions

         

redskins80

6:18 pm on Sep 2, 2011 (gmt 0)

10+ Year Member



I was trying to login to a site remotely. I have successfully done that and the landing page opens properly and i can extract all info fromo it. Problem is, when i click any link, the website logs me out! Earlier the link was relative to my domain, now ive changed it to the website domain but still the problem persists.. Im attaching the code for you to see how ive sent cookies.
I have executed another curl_exec to another url within the site, but the website logs me off!


<html>
<head>
<base href="http://site.net/" />
<body>
<?php
$username = $_POST["uname"];
$password = $_POST["pass"];
$fields = "username=" . $username . "&password=" . $password . "&Login.x=61&Login.y=15";
$ch=curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_URL, 'http://www.amizone.net/amizone/default.aspx');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "ASPSESSIONIDSQADDRBQ=OCALKIGABGLPCJLKMGIKJLLF");
curl_setopt($ch, CURLOPT_COOKIEFILE, "ASPSESSIONIDSQADDRBQ=OCALKIGABGLPCJLKMGIKJLLF");
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000 );
curl_setopt($ch, CURLOPT_TIMEOUT, 10000 );
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8' );
curl_setopt($ch, CURLOPT_AUTOREFERER, 1 );
curl_setopt ($ch, CURLOPT_REFERER, "http://www.site.net/");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
ob_start();
$raw_data=curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http:/site.net/amizone/WebForms/TimeTable/StudentTimeTableForWeek.aspx');
$ttable = curl_exec($ch);
ob_end_clean();
echo $ttable;
//curl_close($ch);
//$raw_data = preg_replace('/\s(1,)/',' ',$raw_data); //clean it up
//echo $raw_data;
//$raw_data = stripslashes($raw_data);
//$raw_data = explode("<strong>",$raw_data);
//2 3 and 4
//echo htmlentities($raw_data[4]);
?>
</body>
</html>


Note: I have taken the cookie name from 'LiveHttpHeaders', an extension for firefox.
What am i missing? Any help would be greatly appreciated!
Thanks in advance.

rainborick

2:14 pm on Sep 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It looks like the site you're accessing sets a Session ID for each user, but your script is setting the cookie for the Session ID to a specific value from your test with LiveHttpHeaders - which is then being rejected by the website as invalid. I think you need to update your script to support cookies natively.

redskins80

2:10 pm on Sep 5, 2011 (gmt 0)

10+ Year Member



okay i think i understood what ure saying.. But even if i try to put in any file name in cookiejar and cookiefile such as cookie.txt, it does the same thing. Ive also given full rights (777) to the folder where its been stored.
I dont know where im going wrong..