cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: windows cookie problem

From: Jon Aston <JonRAston_at_hotmail.com>
Date: Wed, 15 Mar 2006 13:34:11 -0600

S B wrote:
> I have problems retriving cookies using php and curl.
>
> Server configuration:
> PHP Version 4.3.10
> Apache 1.3
> libcurl/7.11.2 OpenSSL/0.9.7c zlib/1.1.4
> windows XP Professional
>
> Script:
>
> <?php
> $url = "http://www.google.com";
> $file = rand(1000, 9999);
> $path = "coky/".$file.".txt";
> $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4)
> Gecko/20030624 Netscape/7.1 (ax)";
>
> $ch = curl_init();
> curl_setopt ($ch, CURLOPT_URL, $url);
> curl_setopt ($ch, CURLOPT_COOKIEJAR, $path);
> curl_setopt ($ch, CURLOPT_COOKIEFILE, $path);
> curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
> curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
>
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
> $result = curl_exec ($ch);
> echo curl_error($ch);
> curl_close($ch);
> echo $result;
> ?>
>
> when I acces the cookie folder it is empty, no cookies are saved, not
> even the cookie file is made.
>
> If I use the same scrip! t on a linux box the cookies are saved ok,
> can you please hlep me. What is wrong?
> I don`t have linux at home and I don`t know how to use it this is why
> I need to build my server on a windows box.
>
> ------------------------------------------------------------------------
> Yahoo! Mail
> Bring photos to life! New PhotoMail
> <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=39174/*http://photomail.mail.yahoo.com>
> makes sharing a breeze.
> ------------------------------------------------------------------------
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
I have to work on a win environment a lot and this works for me

$mypath = getcwd();
$mypath = preg_replace('/\\\\/', '/', $mypath);
$cookie_file_path = "$mypath/cookie.txt";
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)";
$URL = "http://www.google.com";
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$URL);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-03-15