Re: Reuse cookie vars

From: Date: Tue, 26 Feb 2002 23:03:58 +0000
Subject: Re: Reuse cookie vars
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86329@lists.php.net to get a copy of this message
No worries, I fixed it... For anyone who is interrested, here is the script: function get_header($url, $user_agent, $postvars="") { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); if (isset($postvars)) { curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars); } curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); $fp = fopen ("d:/inetpub/wwwroot/curl/test/cookieFileName.txt", "w"); curl_setopt ($ch, CURLOPT_WRITEHEADER, $fp); curl_exec ($ch); curl_close ($ch); fclose ($fp); } function get_page($url, $user_agent, $postvars="") { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); if (isset($postvars)) { curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars); } curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_COOKIEFILE, "d:/inetpub/wwwroot/curl/test/cookieFileName.txt"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($ch); curl_close ($ch); return $result; } // VARS $url1 = "http://mydomain.com/login.php; $url2 = "http://mydomain.com/otherpage.php; $postvars = "user=user&pass=password"; $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; // Log in get_page($url, $user_agent, $postvars); // Get the page echo get_page($url2, $user_agent, ""); // Tobias "Tobias Talltorp" <tobias@talltorp.com> wrote in message news:20020226175850.78561.qmail@pb1.pair.com... > ( Code at the bottom of the message) > I logged in to a page, using the Curl-extension. > I want to use the vars set in the cookie to continue being logged in and > download another page. > > In regular Curl, I need to save the headers, containing the cookie > information, to a file. > In the next step I need to use that file to fake the cookies... > > In regular Curl I use this to dump the headers to a file: > --dump-header "c:\curl\headers.txt" > > How would I do this using the Curl-extension? > > Any thoughts? > // Tobias > > //////////////////// > // Login > $url = "http://mydomain.com/login.php"; > $postvars = "user=joeuser&pass=password"; > $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; > > $ch = curl_init(); > curl_setopt ($ch, CURLOPT_URL, $url); > curl_setopt ($ch, CURLOPT_POST, 1); > curl_setopt ($ch, CURLOPT_POSTFIELDS, $postvars); > curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); > // Here I get the headers, but waht to do with them? > curl_setopt ($ch, CURLOPT_HEADER, 1); > curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); > > // Somewhere here would be nice to save the cookies to a file > > curl_exec ($ch); > curl_close ($ch); > > //////////////////// > // Download next page > $url = "http://mydomain.com/otherpage.php"; > $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; > > > $ch = curl_init(); > curl_setopt ($ch, CURLOPT_URL, $url); > curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); > curl_setopt ($ch, CURLOPT_HEADER, 1); > curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); > > // Read the headers in the saved file and use them to fake cookies > > $result = curl_exec ($ch); > curl_close ($ch); > echo $result; > > >

« previous php.general (#86329) next »