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

curl-and-php

Having trouble with COOKIE_JAR and COOKIE_FILE

From: Josh Halstead <manchild85_at_hotmail.com>
Date: Tue, 18 Jan 2005 17:22:23 -0600

Hi I'm a relatively new to curl/libcurl (just started 2 days ago) and I am
having a problem with cookies in PHP. I can successfully execute my commands
on the command line but when i use COOKIE_JAR and COOKIE_FILE my 'entry
expires'. Here is the technical data that might help

PHP File: (Note: this is not 100% finished but i wanted to get the curl
connections done before i moved on. Therefore that fwrites() at the end will
eventually be moved but right now they serve for debugging)

web server libcurl/curl version: libcurl/7.12.0 OpenSSL/0.9.6 zlib/1.1.4
web server OS: linux
web server php version: 4.3.10

my comp curl version: curl 7.12.3 <i386-pc-win32> libcurl/7.12.3 zlib/1.2.1
my comp os: win XP home edition sp2
no php/apache/etc installed on home comp

$ch = curl_init();
$postData = "login=manchild&pwd=foobar&validation=&x=0&y=0&=enter";
$refererAddress = "http://blitz.the-reincarnation.com/perl/login.pl";
$blitzLogin2Address = "http://blitz.the-reincarnation.com/perl/login2.pl";

curl_setopt($ch, CURLOPT_URL, "$blitzLogin2Address");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "$blitzCookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "$blitzCookie");
curl_setopt($ch, CURLOPT_REFERER, "$refererAddress");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postData");

curl_exec($ch);
curl_close($ch);
unset($ch);

/*
#########################################
##### END Log into the blitz server #####
#########################################
*/

/*
##########################################
##### BGN Move to complete rank list #####
##########################################
*/

$ch = curl_init();
$refererAddress = "http://blitz.the-reincarnation.com/cgi-bin/rank.cgi";
$blitzCompleteRankListAddress =
"http://blitz.the-reincarnation.com/cgi-bin/rank.cgi?mode=all";

curl_setopt($ch, CURLOPT_URL, "$blitzCompleteRankListAddress");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, "$blitzCookie");
curl_setopt($ch, CURLOPT_REFERER, "$refererAddress");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$completeBlitzRankList = curl_exec($ch);
curl_close($ch);
unset($ch);

/*
##########################################
##### END Move to complete rank list #####
##########################################
*/

/*
#######################################
##### BGN Move to guild rank list #####
#######################################
*/

$ch = curl_init();
$refererAddress
="http://blitz.the-reincarnation.com/cgi-bin/guildofterra.cgi";
$blitzGuildRankAddress =
"http://blitz.the-reincarnation.com/cgi-bin/guildrank.cgi";

curl_setopt($ch, CURLOPT_URL, "$blitzGuildRankAddress");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, "$blitzCookie");
curl_setopt($ch, CURLOPT_REFERER, "refererAddress");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$blitzGuildRankList = curl_exec($ch);
curl_close($ch);
unset($ch);

/*
#######################################
##### END Move to guild rank list #####
#######################################
*/

$completeBlitzRankListFile = 'completeBlitzRankListFile.txt';
$fp = fopen($completeBlitzRankListFile, "a");
fwrite($fp, "$completeBlitzRankList");
fclose($fp);

$blitzGuildRankListFile = 'completeGuildRankListFile.txt';
$fpp = fopen($blitzGuildRankListFile, "a");
fwrite($fpp, "$blitzGuildRankList");
fclose($fpp);

Okay that is the PHP File and I explain what I have tried and what didnt
work. I tried using a absolute path in COOKIE_JAR and COOKIE_FILE. I have
tried using a relative path in both. Also I have uploaded a verified cookie
that worked while I used curl through the command line. Then after searching
a bit on google i tried just storing the cookies in a variable. All failed.
Actually the script DOES login to the site but upon moving to a new page it
says "Your Entry Has Expired" which means something went wrong :)

Here is some data from liveHTTPheaders in firefox.

******This goes with the login section of the code******

http://blitz.the-reincarnation.com/perl/login2.pl

POST /perl/login2.pl HTTP/1.1
Host: blitz.the-reincarnation.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://blitz.the-reincarnation.com/perl/login.pl
Cookie:
phpbb2tr_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A2%3A%2218%22%3B%7D;
phpbb2mysql_data=02fc4982d328f721eb7ae4335cd7b0cd;
phpbb2tr_sid=cbb591de2f869cd30d922922ce5aa1ee;
phpbb2tr_t=a%3A4%3A%7Bi%3A4501%3Bi%3A1106087136%3Bi%3A4519%3Bi%3A1106087153%3Bi%3A4518%3Bi%3A1106087742%3Bi%3A3229%3Bi%3A1106087911%3B%7D;
uid=ac7802abdc09594693eaa8c409a7b22d; mage=manchild; mageid=4884;
sessionid=bf55c23e82c5a111f5f75cb87928ebda
Content-Type: application/x-www-form-urlencoded
Content-Length: 56
login=manchild&pwd=foobar&validation=&x=22&y=16&=enter
HTTP/1.x 302 Found
Date: Tue, 18 Jan 2005 23:06:19 GMT
Server: Apache/1.3.31 (Unix) mod_perl/1.28
Set-Cookie: uid=f17c6c3bbde510093f06b6181d5925cc; path=/
Set-Cookie: mage=manchild; path=/
Set-Cookie: mageid=4884; path=/
Set-Cookie: sessionid=8a852138e52089a86662ff8a9d9267ff; path=/
Set-Cookie: phpbb2mysql_data=02fc4982d328f721eb7ae4335cd7b0cd; path=/;
expires=Thursday, 25-Apr-2005 00:40:33 GMT
Location: ../cgi-bin/mainmenu.cgi
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1
----------------------------------------------------------
http://blitz.the-reincarnation.com/cgi-bin/mainmenu.cgi

GET /cgi-bin/mainmenu.cgi HTTP/1.1
Host: blitz.the-reincarnation.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://blitz.the-reincarnation.com/perl/login.pl
Cookie:
phpbb2tr_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A2%3A%2218%22%3B%7D;
phpbb2mysql_data=02fc4982d328f721eb7ae4335cd7b0cd;
phpbb2tr_sid=cbb591de2f869cd30d922922ce5aa1ee;
phpbb2tr_t=a%3A4%3A%7Bi%3A4501%3Bi%3A1106087136%3Bi%3A4519%3Bi%3A1106087153%3Bi%3A4518%3Bi%3A1106087742%3Bi%3A3229%3Bi%3A1106087911%3B%7D;
uid=f17c6c3bbde510093f06b6181d5925cc; mage=manchild; mageid=4884;
sessionid=8a852138e52089a86662ff8a9d9267ff

HTTP/1.x 200 OK
Date: Tue, 18 Jan 2005 23:06:19 GMT
Server: Apache/1.3.31 (Unix) mod_perl/1.28
Pragma: no-cache
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------

******This goes with the MOVE to rank list section******

http://blitz.the-reincarnation.com/cgi-bin/rank.cgi?mode=all

GET /cgi-bin/rank.cgi?mode=all HTTP/1.1
Host: blitz.the-reincarnation.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie:
phpbb2tr_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A2%3A%2218%22%3B%7D;
phpbb2mysql_data=02fc4982d328f721eb7ae4335cd7b0cd;
phpbb2tr_sid=cbb591de2f869cd30d922922ce5aa1ee;
phpbb2tr_t=a%3A4%3A%7Bi%3A4501%3Bi%3A1106087136%3Bi%3A4519%3Bi%3A1106087153%3Bi%3A4518%3Bi%3A1106087742%3Bi%3A3229%3Bi%3A1106087911%3B%7D;
uid=f17c6c3bbde510093f06b6181d5925cc; mage=manchild; mageid=4884;
sessionid=8a852138e52089a86662ff8a9d9267ff

HTTP/1.x 200 OK
Date: Tue, 18 Jan 2005 23:11:11 GMT
Server: Apache/1.3.31 (Unix) mod_perl/1.28
Pragma: no-cache
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------

******This goes with MOVE to guild rank list******

http://blitz.the-reincarnation.com/cgi-bin/guildrank.cgi

GET /cgi-bin/guildrank.cgi HTTP/1.1
Host: blitz.the-reincarnation.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie:
phpbb2tr_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A2%3A%2218%22%3B%7D;
phpbb2mysql_data=02fc4982d328f721eb7ae4335cd7b0cd;
phpbb2tr_sid=cbb591de2f869cd30d922922ce5aa1ee;
phpbb2tr_t=a%3A4%3A%7Bi%3A4501%3Bi%3A1106087136%3Bi%3A4519%3Bi%3A1106087153%3Bi%3A4518%3Bi%3A1106087742%3Bi%3A3229%3Bi%3A1106087911%3B%7D;
uid=f17c6c3bbde510093f06b6181d5925cc; mage=manchild; mageid=4884;
sessionid=8a852138e52089a86662ff8a9d9267ff

HTTP/1.x 200 OK
Date: Tue, 18 Jan 2005 23:13:23 GMT
Server: Apache/1.3.31 (Unix) mod_perl/1.28
Pragma: no-cache
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

Alright that is all of the information that i think you will need. I made
sure i set all files that were in my folder to chmod 777 so there wouldnt be
conflicts with permissions. I cant think of anything that i am doing wrong.

thanks for the help,
Josh
Received on 2005-01-19