Login   Register  
PHP Classes
elePHPant
Icontem

Cookies disappearing on certain pages

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  Cookies disappearing on certain pages  >  (Un) Subscribe thread alerts  
Subject:Cookies disappearing on certain pages
Summary:Cookies disappearing on certain pages.
Messages:8
Author:taofik
Date:2010-10-05 05:15:12
Update:2011-01-27 02:29:42
 

  1. Cookies disappearing on certain pages   Reply   Report abuse  
Picture of taofik
taofik
2010-10-05 05:15:12
Your script was very good. maybe this is a mistake in writing my script. I make a request to some page with a specific sequence. all pages successfully requested. but there is a page where cookies are not registered / disappear.

below the header data is successfully requested.

Below is the result of a request header.
This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/Logon
-------------------------------------------------------------------------------------------------------------------------
Host: luxonline.luxottica.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Content-Type: application/x-www-form-urlencoded
Content-Length: 129
http/1.1 200 ok:
date: Tue, 05 Oct 2010 05:11:10 GMT
server: WebSphere Application Server/5.0
expires: Thu, 01 Dec 1994 16:00:00 GMT
set-cookie: WC_USERSESSION_743844=743844%2c%2d1%2cEUR%2c%2d2000%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2c%5b10001%7c10001%7c10001%7cnull%7c%2d2000%5d%2cB6Jmk9AIFmMSyp0GFq9oRu2%2bzRA%3d;Path=/
cache-control: private
transfer-encoding: chunked
content-type: text/html; charset=UTF-8
content-language: it-IT


Below is the result of a request header.
This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogBrandSelection
-------------------------------------------------------------------------------------------------------------------------
Host: luxonline.luxottica.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Content-Type: application/x-www-form-urlencoded
Content-Length: 110
http/1.1 200 ok:
date: Tue, 05 Oct 2010 05:11:17 GMT
server: WebSphere Application Server/5.0
expires: Thu, 01 Dec 1994 16:00:00 GMT
set-cookie: WC_USERSESSION_743844=743844%2c%2d1%2cEUR%2c%2d2000%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2c%5b10001%7c10001%7c10001%7cnull%7c%2d2000%5d%2cB6Jmk9AIFmMSyp0GFq9oRu2%2bzRA%3d;Path=/
cache-control: private
transfer-encoding: chunked
content-type: text/html; charset=UTF-8
content-language: it-IT


Below is the result of a request header.
This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection
-------------------------------------------------------------------------------------------------------------------------
Host: luxonline.luxottica.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Content-Type: application/x-www-form-urlencoded
Content-Length: 233
http/1.1 200 ok:
date: Tue, 05 Oct 2010 05:11:20 GMT
server: WebSphere Application Server/5.0
expires: Thu, 01 Dec 1994 16:00:00 GMT
set-cookie: WC_USERSESSION_743844=743844%2c%2d1%2cEUR%2c%2d2000%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2c%5b10001%7c10001%7c10001%7cnull%7c%2d2000%5d%2cB6Jmk9AIFmMSyp0GFq9oRu2%2bzRA%3d;Path=/
cache-control: private
transfer-encoding: chunked
content-type: text/html; charset=UTF-8
content-language: it-IT


Below is the result of a request header.
This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogSKUSelection
Here, the cookie disappears. In contrast to the request on another page, here there is no cookie.
-------------------------------------------------------------------------------------------------------------------------
Host: luxonline.luxottica.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Content-Type: application/x-www-form-urlencoded
Content-Length: 374
http/1.1 200 ok:
date: Tue, 05 Oct 2010 05:11:25 GMT
server: WebSphere Application Server/5.0
transfer-encoding: chunked
content-type: text/html; charset=UTF-8
content-language: it-IT


Below is the result of a request header.
This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection
Here cookies are still available!
-------------------------------------------------------------------------------------------------------------------------
Host: luxonline.luxottica.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Content-Type: application/x-www-form-urlencoded
Content-Length: 233
http/1.1 200 ok:
date: Tue, 05 Oct 2010 05:11:29 GMT
server: WebSphere Application Server/5.0
expires: Thu, 01 Dec 1994 16:00:00 GMT
set-cookie: WC_USERSESSION_743844=743844%2c%2d1%2cEUR%2c%2d2000%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2cnull%2c%5b10001%7c10001%7c10001%7cnull%7c%2d2000%5d%2cB6Jmk9AIFmMSyp0GFq9oRu2%2bzRA%3d;Path=/
cache-control: private
transfer-encoding: chunked
content-type: text/html; charset=UTF-8
content-language: it-IT

  2. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2010-10-05 05:44:43 - In reply to message 1 from taofik
Can you provide a minimal example script using the class to access those pages that demonstrates the problem you are experiencing?

  3. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of taofik
taofik
2010-10-06 04:06:44 - In reply to message 2 from Manuel Lemos
sorry, the code is still messy. I'm still experimenting and learning your modules to access the web which I will access. so, I have not made a neat class.

This is my code.



<?php
require("http.php");

set_time_limit(0);
$http=new http_class;

$http->timeout=0;
$http->data_timeout=0;
$http->debug=0;
$http->html_debug=0;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$http->follow_redirect=1;
$http->redirection_limit=5;
$http->exclude_address="";
$http->prefer_curl=0;

$user="";
$password="";
$realm=""; /* Authentication realm or domain */
$workstation=""; /* Workstation for NTLM authentication */
$authentication=(strlen($user) ? UrlEncode($user).":".UrlEncode($password)."@" : "");

$url="http://luxonline.luxottica.com/webapp/wcs/stores/servlet/Logon";
echo "<hr>Below is the result of a request header.<br>";
echo "This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/Logon";
echo "-------------------------------------------------------------------------------------------------------------------------<hr><br>";

$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
unset($arguments["PostValues"]);
$arguments["PostValues"]=array(
"storeId"=>"10001",
"langId"=>"-1",
"reLogonURL"=>"LogonForm",
"URL"=>"HomePage",
"reserverd_viewname"=>"HomePage",
"logonId"=>"nlcu00123680",
"logonPassword"=>"xxxxxx"
);

$arguments["Referer"]="";
if(strlen($realm))
$arguments["AuthRealm"]=$realm;

if(strlen($workstation))
$arguments["AuthWorkstation"]=$workstation;

$http->authentication_mechanism=""; // force a given authentication mechanism;

$arguments["Headers"]["Pragma"]="nocache";
$error=$http->Open($arguments);

if($error=="")
{
$error=$http->SendRequest($arguments);

if($error=="")
{
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n<br>";
}
flush();
$headers=array();
$error=$http->ReadReplyHeaders($headers);
if($error=="")
{
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n<br>";
}
flush();
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
}
flush();
}
}

$http->Close();
}


/* NEXT PAGE --------------------------------------------------------------------------------------*/
$url="http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogBrandSelection";
echo "<hr>Below is the result of a request header.<br>";
echo "This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogBrandSelection";
echo "-------------------------------------------------------------------------------------------------------------------------<hr><br>";

$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
unset($arguments["PostValues"]);
$arguments["PostValues"]=array(
"storeId"=>"10001",
"langId"=>"-1",
"reserverd_prevUrl"=>"CatalogBrandSelection",
"reserverd_url"=>"home",
"reserverd_viewname"=>"HomePage"
);

$arguments["Referer"]="";
if(strlen($realm))
$arguments["AuthRealm"]=$realm;

if(strlen($workstation))
$arguments["AuthWorkstation"]=$workstation;

$http->authentication_mechanism=""; // force a given authentication mechanism;
$arguments["Headers"]["Pragma"]="nocache";

$error=$http->Open($arguments);

if($error=="")
{
$error=$http->SendRequest($arguments);

if($error=="")
{
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n<br>";
}
flush();

$headers=array();
$error=$http->ReadReplyHeaders($headers);
if($error=="")
{
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n<br>";
}
flush();
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
}
flush();
}
}

$http->Close();
}

/* NEXT PAGE --------------------------------------------------------------------------------------*/
$url="http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection";
echo "<hr>Below is the result of a request header.<br>";
echo "This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection";
echo "-------------------------------------------------------------------------------------------------------------------------<hr><br>";

$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
unset($arguments["PostValues"]);
$arguments["PostValues"]=array(
"storeId"=>"10001",
"langId"=>"-1",
"reserverd_prevUrl"=>"Home",
"reserverd_url"=>"CatalogBrandSelection",
"reserverd_viewname"=>"CatalogBrandSelectionPage",
"brand_id"=>"10559",
"catalog_inOrderSheet"=>"T",
"catalog_accesss_from_brand_selection"=>"T",
"PriceVisibilitySelection"=>"002"
);

$arguments["Referer"]="";
if(strlen($realm))
$arguments["AuthRealm"]=$realm;

if(strlen($workstation))
$arguments["AuthWorkstation"]=$workstation;

$http->authentication_mechanism=""; // force a given authentication mechanism;

$arguments["Headers"]["Pragma"]="nocache";
$error=$http->Open($arguments);

if($error=="")
{
$error=$http->SendRequest($arguments);

if($error=="")
{
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n<br>";
}
flush();

$headers=array();
$error=$http->ReadReplyHeaders($headers);
if($error=="")
{
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n<br>";
}
flush();
$output = "";
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
$output .= $body;
}
flush();
}
}

$http->Close();
}

/* NEXT PAGE --------------------------------------------------------------------------------------*/
$url="http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogSKUSelection";
echo "<hr>Below is the result of a request header.<br>";
echo "This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogSKUSelection<br>";
echo "Here, the cookie disappears. In contrast to the request on another page, here there is no cookie.";
echo "-------------------------------------------------------------------------------------------------------------------------<hr><br>";

$error=$http->GetRequestArguments($url,$arguments);

$arguments["RequestMethod"]="POST";
unset($arguments["PostValues"]);
$arguments["PostValues"]=array(
"storeId"=>"10001",
"reserverd_prevUrl"=>"CatalogBrandSelection",
"reserverd_url"=>"CatalogModelSelection",
"reserverd_viewname"=>"CatalogModelSelectionPage",
"langId"=>"-1",
"model_id"=>"357161",
"control_updBackProps"=>"T",
"update_order_sheet_properties"=>"",
"update_model_rendering"=>"",
"brand_id"=>"10559",
"PriceVisibilitySelection"=>"002",
"catalog_access_from_simple_search"=>"T",
"ssearch_key"=>"",
"model_rendering"=>"001",
"catalog_inOrderSheet"=>"T"
);

$arguments["Referer"]="";
if(strlen($realm))
$arguments["AuthRealm"]=$realm;

if(strlen($workstation))
$arguments["AuthWorkstation"]=$workstation;

$http->authentication_mechanism=""; // force a given authentication mechanism;
$arguments["Headers"]["Pragma"]="nocache";
$error=$http->Open($arguments);

if($error=="")
{
$error=$http->SendRequest($arguments);

if($error=="")
{
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n<br>";
}
flush();

$headers=array();
$error=$http->ReadReplyHeaders($headers);
if($error=="")
{
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n<br>";
}
flush();
$output = "";
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
$output .= $body;
}
flush();
}
}

$http->Close();
}


/* NEXT PAGE --------------------------------------------------------------------------------------*/

$url="http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection";
echo "<hr>Below is the result of a request header.<br>";
echo "This is request from http://luxonline.luxottica.com/webapp/wcs/stores/servlet/CatalogModelSelection<br>";
echo "Here cookies are still available!";
echo "-------------------------------------------------------------------------------------------------------------------------<hr><br>";


$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
unset($arguments["PostValues"]);
$arguments["PostValues"]=array(
"storeId"=>"10001",
"langId"=>"-1",
"reserverd_prevUrl"=>"Home",
"reserverd_url"=>"CatalogBrandSelection",
"reserverd_viewname"=>"CatalogBrandSelectionPage",
"brand_id"=>"10559",
"catalog_inOrderSheet"=>"T",
"catalog_accesss_from_brand_selection"=>"T",
"PriceVisibilitySelection"=>"002"
);

$arguments["Referer"]="";
if(strlen($realm))
$arguments["AuthRealm"]=$realm;

if(strlen($workstation))
$arguments["AuthWorkstation"]=$workstation;

$http->authentication_mechanism=""; // force a given authentication mechanism;
$arguments["Headers"]["Pragma"]="nocache";
$error=$http->Open($arguments);

if($error=="")
{
$error=$http->SendRequest($arguments);

if($error=="")
{
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n<br>";
}
flush();

$headers=array();
$error=$http->ReadReplyHeaders($headers);
if($error=="")
{
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n<br>";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n<br>";
}
flush();
$output = "";
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
$output .= $body;
}
flush();
}
}

$http->Close();
}

if(strlen($error))
echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n";
?>

  4. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2010-10-09 04:51:26 - In reply to message 3 from taofik
I looked at this and do not see what is the problem you think there is.

You are displaying the request and response headers. Actually the class does not store all the request headers in the request_headers variable. For instance picked cookies sent to the server are not returned there.

If you want to set the cookies sent to the server, you would better set the debug variable to 1.

From what I checked, all cookies sent by the server in previous requests are sent back to the server in the next request because those are session cookies and do not expired unless the server sets their expires date in the past, which does not happen.

  5. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Marti Ficus
Marti Ficus
2011-01-11 02:40:27 - In reply to message 4 from Manuel Lemos
I ran into something similar. It appears cookie attributes with a capitalized first character (e.g., "Domain=" instead of "domain=") are not recognized. Changing http.php line 1512 to down-case the attribute names before the switch statement allows the cookies to be delivered:

while(($name=strtolower(trim(UrlDecode($this->Tokenize("=")))))!="")

Sorry if posting this here isn't the right way to report this -- I didn't see another way to submit a code modification.


  6. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2011-01-12 02:26:39 - In reply to message 5 from Marti Ficus
Can you provide the URL of a site that sets cookies in that way so I can try to reproduce the problem?

  7. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Marti Ficus
Marti Ficus
2011-01-12 13:07:31 - In reply to message 6 from Manuel Lemos
www.constantcontact.com

It capitalizes all of the attributes: Domain, Path, Expires. RFC 2965 says attribute names are case-insensitive.

  8. Re: Cookies disappearing on certain pages   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2011-01-27 02:29:42 - In reply to message 7 from Marti Ficus
OK, only now I had time to look into this.

I just fixed the code to make it case sensitive. I hope it works now. Thanks for reporting.