Forum Moderators: coopster
I am having an issue with saving the session ID so I can use it later as I move to the next page on a site. I am able to output the session ID on screen. Here is my code:
$url = 'http://#*$!/#*$!/TracingLogin.aspx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__VIEWSTATE=$viewstate&ctl00\$ContentPlaceHolder1\$txtUserName=#*$!x&ctl00\ $ContentPlaceHolder1\$txtPassword=#*$!x&ctl00\$ContentPlaceHolder1\$cmdLogin= Submit&__EVENTVALIDATION=$validation");curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
The header output is:
HTTP/1.1 200 OK
Date: Wed, 14 Nov 2007 17:43:33 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: ASP.NET_SessionId=nltmbbb4fqknx355ry4hh545; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 8579
I have tried the following but it does not seem to work.
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
Thank you.
[edited by: dreamcatcher at 7:38 pm (utc) on Nov. 15, 2007]
[edit reason] Fixed side scroll. [/edit]
Have you tried -
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
To see if that works? Maybe a problem with dirname().
The next thing may be that php (operating an nobody) doesnt have permission to create or write to that file.
Are you getting any error messages? If so what are they?
Is the cookie.txt file being created?
Also the COOKIEJAR description is
The name of a file to save all internal cookies to when the connection closes.and in your code the connection is not closed. So try calling curl_close($ch); and see if it works then.