473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple cookie reading problem

Hi all, this is probably stupidly easy but I'm struggling.

I am trying to understand why cookies only appear to be readable when a
web page is retrieved by *typing the url into the browser's address
box* but NOT when the same page is accessed *via a link from another
page*. I probably don't fully understand the mechanics of an HTTP
request...

Example:

The first page sets a persistent cookie:

<?php
$value = 'something';
setcookie("TestCookie", $value, time()+(24*365*3600));
?>

and contains a link - <a href="cookie_test.php?">Link to cookie
test</a>

The second page [cookie_test.php] contains the following code:

<?php
print "COOKIE DATA: <br />";
foreach ( $_COOKIE as $cookie_name =$cookie_value ) {
print "$cookie_name = $cookie_value <br />";
}
?>

When a) viewing cookie_test.php, using either Firefox 2.0 or IE7, via
the link from page one, the cookie data does not print out. But b) by
entering cookie_test.php into the address box and pressing return, this
causes the browser to display the cookie contents.
PHP Version 4.3.10

Could I have an explanation please and how do I retrieve cookie data in
case (a) ?

Thanks for your help...

Nov 5 '06 #1
1 1537


On Nov 5, 10:59 am, "4site" <ian4s...@hotmail.comwrote:
Hi all, this is probably stupidly easy but I'm struggling.

I am trying to understand why cookies only appear to be readable when a
web page is retrieved by *typing the url into the browser's address
box* but NOT when the same page is accessed *via a link from another
page*. I probably don't fully understand the mechanics of an HTTP
request...

Example:

The first page sets a persistent cookie:

<?php
$value = 'something';
setcookie("TestCookie", $value, time()+(24*365*3600));
?>

and contains a link - <a href="cookie_test.php?">Link to cookie
test</a>

The second page [cookie_test.php] contains the following code:

<?php
print "COOKIE DATA: <br />";
foreach ( $_COOKIE as $cookie_name =$cookie_value ) {
print "$cookie_name = $cookie_value <br />";}?>

When a) viewing cookie_test.php, using either Firefox 2.0 or IE7, via
the link from page one, the cookie data does not print out. But b) by
entering cookie_test.php into the address box and pressing return, this
causes the browser to display the cookie contents.
PHP Version 4.3.10

Could I have an explanation please and how do I retrieve cookie data in
case (a) ?

Thanks for your help...
Hey 4site,
Sounds like everything should work fine, but the browsers might be
caching cookie_test.php without the information on it. Have you tried
completely refreshing the page after cookie_test.php loads empty? You
might also check out the manual for header() as there is a good example
for stopping browsers from caching pages.
Good luck, Blayde

Nov 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
8942
by: Jochen Daum | last post by:
Hi! I have a function in a lot of pages, which redirects to a new page, if a form has been submitted: if (!(defined("DEBUG_INSERT") && DEBUG_INSERT) && !(defined("DEBUG_UPDATE") &&...
2
2988
by: Syed Ghayas | last post by:
Hi, I've been having problem writing a cookie. Everything goes ok but when I supply the .Path property to "/" It just write the cookie when there is no cookie present, but when I try to update the...
14
3232
by: Alec S. | last post by:
Hi, I'm using JavaScript and Cookies for some customization in a web page. There may be several values in the cookie with names that are not known at runtime. I need a way of deleting them. ...
3
11096
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
5
1793
by: Logickle | last post by:
Hi, all. I'm working on an application which requires communicating session info between separate web apps running on the same web server. The out of process server method sounded ideal, and...
0
1221
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
9
5487
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
29
2981
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
8
2043
by: LayneMitch via WebmasterKB.com | last post by:
I'm supposed to develop a page that asks info as form values and when you hit "submit" it takes you to a page that reads the values you entered into the first page and displays those values in a...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.