SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    RS, Brazil
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cURL + Cookies = nightmare

    Hello,

    this is the first time I'm using cURL and I need the following:

    - I need to login on a external site
    - record the generated cookie
    - start using this cookie

    The page i'm trying to signing in generates a different sesison cookie each time.

    It looks like a pretty usual use for cURL. But, if I try using:
    Code:
    		curl_setopt( $cCURL, CURLOPT_COOKIEJAR, 'cookie.txt');
    		curl_setopt( $cCURL, CURLOPT_COOKIEFILE, 'cookie.txt');
    it doesn't work. The cookie.txt has a value string diferent from the one is used in my browser. As I didn't find any "one-line" command to use the retrieved cookie, the only way to make it work, is to replace CURLOPT_COOKIEFILE with:
    Code:
    $file=file("cookie.txt");		
    		$lastLine=$file[count($file)-1];
    		$words=explode("\t",$lastLine);
    		$lastWord=substr($words[count($words)-1],0,32);	
    		setcookie('frontend', $lastWord,time()+60000,'/');
    		curl_setopt( $cCURL, CURLOPT_COOKIE, 'frontend='.$lastWord);
    it works, but it doesn't look like this is the right way to do this.

    Is there any better option? Anyone have a clue on why this didn't work with COOKIEFILE?

  2. #2
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you'll find you cannot set cookies for a different domain.

    You can however set them for subdomains.

    So for instance:

    xx.com can't set a cookie for yy.com
    xx.com can set a cookie for yy.xx.com or vice versa

    That may be your problem..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •