Page 1 of 1

Why I got two defferent values of $_COOKIE on the same page?

Posted: Thu Apr 29, 2010 4:51 am
by xiaoxuxu_one
Hi,
I get a strange problem:
I set a Cookie when I logined(such as : setcookie(‘CustomField1’,'xx zz dd ',2545063036);),then turn to main page。There is a area filled by using AJAX in the main page。In the main page and the AJAX area,all use print_r($_COOKIE);

The result of the main page is :
Array ( [AJSTAT_ok_times] => 11 [PHPSESSID] => 7c9d3f4120455baf58e0293e28a05a80 )

The result of the AJAX area in the main page is :
Array ( [CustomField1] => a19YQEtoVFZHTVNcX0JObWQay3tJylusPAiYJmQEY5VQoWGj9eC0RPO11bQ09vXThcV0RIPF1ZQUg [AJSTAT_ok_times] => 11 [PHPSESSID] => 7c9d3f4120455baf58e0293e28a05a80 )

The result of the AJAX area is right。Why the main page does get another values?

The URL of the main page is http://localhost:8078/main/default (Call the form of /main/default )
The URL of the AJAX area http://localhost:8078/main/default/Ajax/Sub/index (Call the form of /main/default/Ajax/Sub/index)


using Php5.2, the setting about Session and Cookie in the php.ini is following:
[Session]
session.save_handler = files

session.save_path = c:\webroot\tmp

session.use_cookies = 1

session.name = PHPSESSID

session.auto_start = 1

session.cookie_lifetime = 0

session.cookie_path = /

session.cookie_domain =

session.cookie_httponly =

session.serialize_handler = php

session.gc_probability = 1
session.gc_divisor = 100

session.gc_maxlifetime = 36000

session.bug_compat_42 = 0
session.bug_compat_warn = 1

session.referer_check =

session.entropy_length = 0

session.entropy_file =

session.cache_limiter = nocache

session.cache_expire = 180

session.use_trans_sid = 0

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

The Setting in Apache is following,using URL Rewrite
<VirtualHost *:8078>
ServerName "localhost"
DocumentRoot "c:/WebRoot"
<Directory "/WebRoot">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Alias /htm "/WebRoot/htm/index.php"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/htm/?$ /htm/$1
</IfModule>

Alias /main "/WebRoot/main/index.php"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/main/?$ /main/$1
</IfModule>

</VirtualHost>

Re: Why I got two defferent values of $_COOKIE on the same p

Posted: Fri Apr 30, 2010 10:02 am
by katierosy
If you will not get any difficulty in session($_SESSION). You may put some more time on existing issue, you will be able to know it.
It will be good to have a look into how to save session in database then there is a question of session not keeping the state across pages.

Re: Why I got two defferent values of $_COOKIE on the same p

Posted: Sat May 01, 2010 1:28 am
by xiaoxuxu_one
I tried to publish the application on a local machine, and the application has run at a real server with no problem.So I think the source code should has no problem, and there are some configuration errors with my local machine or my local source code.

The following is HTTP Head, As you'll see, the Set-Cookie command has sent to the client, but when another request has sent, the cookie in it doesn't has the infomation it should has.
=============================
POST /main/default/login.htm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://localhost:8078/main/default/login.htm
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; QQDownload 1.7; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; .NET CLR 3.0.30729; InfoPath.3)
Host: localhost:8078
Content-Length: 58
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: AJSTAT_ok_times=11; PHPSESSID=c805f7aaa2f3dd078c143d2d335ae43c
username=admin&password=1&randcode=op01

HTTP/1.1 200 OK
Date: Sat, 01 May 2010 05:57:57 GMT
Server: Apache/2.2.14 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: CustomField1=a19YQEhjXltFSVNcX0JObWQaARAiYJmQEY5VQoWGj9eC0RPO11bQ09vXF4WTThcV0RIPF1ZQUg; path=/; domain=localhost
Content-Length: 55
Keep-Alive: timeout=15, max=997
Connection: Keep-Alive
Content-Type: text/html; charset=gb2312


GET /main/default HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; QQDownload 1.7; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; .NET CLR 3.0.30729; InfoPath.3)
Host: localhost:8078
Connection: Keep-Alive
Cookie: AJSTAT_ok_times=11; PHPSESSID=c805f7aaa2f3dd078c143d2d335ae43c

HTTP/1.1 200 OK
Date: Sat, 01 May 2010 05:57:57 GMT
Server: Apache/2.2.14 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 65
Keep-Alive: timeout=15, max=997
Connection: Keep-Alive
Content-Type: text/html; charset=gb2312

Re: Why I got two defferent values of $_COOKIE on the same p

Posted: Sat May 01, 2010 1:37 am
by xiaoxuxu_one
And, there is no warning such as " PHP Warning: Cannot modify header information - headers already sent by (output started at .." in php's log file.