P3P & cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IcyNoAngel
Forum Newbie
Posts: 2
Joined: Fri Aug 13, 2004 3:18 am
Location: Romania

P3P & cURL

Post by IcyNoAngel »

Hello !

I have a really ugly problem. I'm trying to connect to a site using cURL, but the server returns to me a page that has a header named P3P, and in the body section of that page it says "Please enable cookies". I've tryed many things, and I think that this header I'm getting is the problem.
I'm not sure how can I enable cookies cause I'm not using a browser, where everything is simple to set. As I've said I'm trying to do this by script using cURL.
Does anyone had this problem before or has an idea on what should I do to pass this cookie check? Maybe I have to send a new header to the server or something, I'm confused.

Thanks for your help !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

curl has an option to set it's acceptance and transmission of cookies.. :: http://www.php.net/curl_setopt :: CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE and CURLOPT_COOKIE depending on your/the remote server's needs..

please post your curl code, and the result from the server, if you need more help.
IcyNoAngel
Forum Newbie
Posts: 2
Joined: Fri Aug 13, 2004 3:18 am
Location: Romania

Post by IcyNoAngel »

OK! Here's my code. I'm making a new var named $toWrite cause I've discovered (using firefox) that there are some cookies that aren't written in the cookie file I provide (I think those are session cookies or something). This aproach doesn't work either. Hope someone can help me.
Thank you for your time.

Code: Select all

<?php 

         $address = "https://www.expedia.com/pub/agent.dll?qscr=logi&ussl=1&BCheck=1&sticky=0&ckie=True&zz=".(time()*1000);

         $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";

         $cu = curl_init();
         curl_setopt($cu, CURLOPT_URL, $address);
         curl_setopt($cu, CURLOPT_USERAGENT, $agent);
         curl_setopt($cu, CURLOPT_HEADER, 1);
         curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($cu, CURLOPT_COOKIEJAR, "cookie");

         $result = curl_exec($cu);
         curl_close ($cu);

         $toWrite = ".expedia.com        TRUE        /        FALSE        1262303999        linfo                    v.3,|0|0|255|1|0||||||||0|0|0||0|0 \n";
         $toWrite .= ".expedia.com        TRUE        /        FALSE        1262303999        COOKIECHECK              1 \n";
         $toWrite .= ".expedia.com        TRUE        /        FALSE        1262303999        accttype                 v.1,3,1 \n";
         $toWrite .= ".expedia.com        TRUE        /        FALSE        1262303999        jscript                  1 \n";
         $toWrite .= ".expedia.com        TRUE        /        FALSE        1262303999        gacct                    v.1,2,212280850 \n";

         $fd = fopen("cookie","a");
         fwrite($fd, $toWrite);
         fclose($fd);

         //open file to get output
         $fd = fopen("content.html","w");
         fwrite($fd, $result);
         fclose($fd);

         //second attempt
         $cu = curl_init();
         curl_setopt($cu, CURLOPT_URL, $address);
         curl_setopt($cu, CURLOPT_USERAGENT, $agent);
         curl_setopt($cu, CURLOPT_HEADER, 1);
         curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($cu, CURLOPT_COOKIEFILE, "cookie");


         $result = curl_exec($cu);
         curl_close ($cu);

         //open file to get output
         $fd = fopen("content1.html","w");
         fwrite($fd, $result);
         fclose($fd);


?>
Post Reply