ainoy31 Posted November 14, 2007 Share Posted November 14, 2007 Hello- I am able log into an ASP site with an username and password. At the same time, I need to save the ASP session ID to a file so I can use it for the next page. My problem is that I am not able to save the session ID to my cookie.txt file. 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_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). '/cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); curl_setopt($ch, CURLOPT_POSTFIELDS, "__VIEWSTATE=$viewstate&ctl00\$ContentPlaceHolder1\$txtUserName=XXXX&ctl00\$ContentPlaceHolder1\$txtPassword=XXXX&ctl00\$ContentPlaceHolder1\$cmdLogin=Submit&__EVENTVALIDATION=$validation"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); echo curl_error($ch); I am able to see the session ID. HTTP/1.1 200 OK Date: Wed, 14 Nov 2007 15:34:30 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Set-Cookie: ASP.NET_SessionId=aziug1idyeszbj45ha3efmnq; path=/; HttpOnly Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 8579 Much appreciation on any suggestions. Thank you. AM Link to comment https://forums.phpfreaks.com/topic/77322-solved-cookie-handling-with-curlopt_cookiefile/ Share on other sites More sharing options...
revraz Posted November 14, 2007 Share Posted November 14, 2007 This is a PHP Forum. Link to comment https://forums.phpfreaks.com/topic/77322-solved-cookie-handling-with-curlopt_cookiefile/#findComment-391479 Share on other sites More sharing options...
ainoy31 Posted November 14, 2007 Author Share Posted November 14, 2007 My issue is not an ASP. I am using the curl method of PHP. Please reply with good suggestions. Link to comment https://forums.phpfreaks.com/topic/77322-solved-cookie-handling-with-curlopt_cookiefile/#findComment-391483 Share on other sites More sharing options...
ainoy31 Posted November 14, 2007 Author Share Posted November 14, 2007 I figure it out. The solution is as follows: I used curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); to store the cookie variable and if I had to go to another page, I used curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); to retrieve my session ID variable. The thing to keep in mind is that check to make sure that PHP has permission to create or write to a file. If not, change the cookie file property to have these permissions. Also, if using the curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'), make sure to close the curl session -> curl_close($ch). Hope this helps someone else as it was a learning experience from me. Thanks. AM Link to comment https://forums.phpfreaks.com/topic/77322-solved-cookie-handling-with-curlopt_cookiefile/#findComment-391701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.