473,569 Members | 2,683 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("Test Cookie", $value, time()+(24*365* 3600));
?>

and contains a link - <a href="cookie_te st.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_na me = $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 1546


On Nov 5, 10:59 am, "4site" <ian4s...@hotma il.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("Test Cookie", $value, time()+(24*365* 3600));
?>

and contains a link - <a href="cookie_te st.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_na me = $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
8949
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") && DEBUG_UPDATE) && !(defined("DEBUG_SELECT") && DEBUG_SELECT)){ if ($_POST){ $_SESSION = $_POST;
2
2992
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 cookie (or overwrite the cookie) it doesnt change it. My requirement to supply the path to "/" because ASP.NET reads it. If I write the cookie...
14
3243
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. For example, if my site is www.test.com and the cookie contains: label1 fob
3
11107
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 behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the...
5
1796
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 very simple to implement as far as I could tell. So I re-configured my apps' web.config and machine.config files from InProc to StateServer, and...
0
1225
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? The following code is a complete page that demonstrates my problem. If you save this as an .aspx and load it in a browser, it tells you it is...
9
5498
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 http://www.developersdex.com ***
29
2985
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 switch/case to take action based on that value in the cookie. I want to set the cookie manually, so I don't need setcookie(). I see that in PHP it...
8
2052
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 message. I can't seem to find where I'm going wrong. Here's the code: Setting Cookie and Form Page: <html><head><title>Problem3</title> <script...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2113
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 we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.