473,725 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

beginner cookie think

hi all,

Trying to get those cookies to work but they wont...

Doing this. Have a page login.php wich tests the user and pass. If they are
correct a cookie is set with one variable like this: setcookie
("cookieUser ", $user);
then the browser is sent with header("Locatio n: spelersPage.php "); to
another page.
I there try to read the cookievariable cookieUser on the spelersPage.php
like this.
<?
$test = $_COOKIE["cookieGebruike r"];
echo "|$test";
?>

without any succes. Someone has an idea. The page is im my Thrusted sites
list...

kind regards
Stijn


Jul 16 '05 #1
3 2869

"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************** @reader1.news.s kynet.be...
hi all,

Trying to get those cookies to work but they wont...

Doing this. Have a page login.php wich tests the user and pass. If they are correct a cookie is set with one variable like this: setcookie
("cookieUser ", $user);
then the browser is sent with header("Locatio n: spelersPage.php "); to
another page.
I there try to read the cookievariable cookieUser on the spelersPage.php
like this.
<?
$test = $_COOKIE["cookieGebruike r"];
echo "|$test";
?>

without any succes. Someone has an idea. The page is im my Thrusted sites
list...

kind regards
Stijn


Your problem is likely due to a limitation to cookies, not php.

A refresh has to have occured before your cookie becomes available to your
environment thus if you were to refresh your browser a couple of times you
should get your cookie. If not, as a test, I tend to use phpinfo(); alot
when doing various tests on form and cookie variables... Try writing the
following few lines to a php script file of its own (call it cookieTest.php
for our example).

<?
// For our test, our cookie will be the words "hello world" followed by the
eleven digit timestamp generated by time();
$ourCookie="hel lo world" . time();
setcookie("ourT estCookie", $ourCookie);
print("<br>1 = The cookie we just set is $ourCookie<br>" );
print("<br>2 = However the cookie that is already baked is:
$_COOKIE[ourTestCookie]");
phpinfo();
?>

View this code in a page of its own... refresh the page a few times and
examine the values that are output - and while you're at it, examine the
output of phpinfo();.

I would expect that you should find something like

1 = The cookie we just set is hello world1234567890 1
2= However the cookie that is already baked is:

The next time your refresh your browser, you should find the output
something like the following

1 = The cookie we just set is hello world1234567891 1
2= However the cookie that is already baked is:hello world1234567890 1

Note that the cookie the first time was sent to the browser but could not be
read yet (until you re-freshed the browser).
Jul 16 '05 #2

----- Original Message -----
From: "Randell D." <yo************ **************@ yahoo.com>
Newsgroups: comp.lang.php
Sent: Friday, September 12, 2003 10:42 PM
Subject: Re: beginner cookie think


"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************** @reader1.news.s kynet.be...
hi all,

Trying to get those cookies to work but they wont...

Doing this. Have a page login.php wich tests the user and pass. If they are
correct a cookie is set with one variable like this: setcookie
("cookieUser ", $user);
then the browser is sent with header("Locatio n: spelersPage.php "); to
another page.
I there try to read the cookievariable cookieUser on the spelersPage.php
like this.
<?
$test = $_COOKIE["cookieGebruike r"];
echo "|$test";
?>

without any succes. Someone has an idea. The page is im my Thrusted sites list...

kind regards
Stijn


Your problem is likely due to a limitation to cookies, not php.

A refresh has to have occured before your cookie becomes available to your
environment thus if you were to refresh your browser a couple of times you
should get your cookie. If not, as a test, I tend to use phpinfo(); alot
when doing various tests on form and cookie variables... Try writing the
following few lines to a php script file of its own (call it

cookieTest.php for our example).

<?
// For our test, our cookie will be the words "hello world" followed by the eleven digit timestamp generated by time();
$ourCookie="hel lo world" . time();
setcookie("ourT estCookie", $ourCookie);
print("<br>1 = The cookie we just set is $ourCookie<br>" );
print("<br>2 = However the cookie that is already baked is:
$_COOKIE[ourTestCookie]");
phpinfo();
?>

View this code in a page of its own... refresh the page a few times and
examine the values that are output - and while you're at it, examine the
output of phpinfo();.

I would expect that you should find something like

1 = The cookie we just set is hello world1234567890 1
2= However the cookie that is already baked is:

The next time your refresh your browser, you should find the output
something like the following

1 = The cookie we just set is hello world1234567891 1
2= However the cookie that is already baked is:hello world1234567890 1

Note that the cookie the first time was sent to the browser but could not be read yet (until you re-freshed the browser).

Hi,

Thanks for your reply. Indeed, when I refresh the page where the cookie is
defined, the cookievariable is set. What is the best way to overcome this
cookielimitatio n? Do I have to use some sort of javascript refresh while the
setcookie page is accessed or is there an other way (pref. in php) to
overcome this problem...
I want to use the cookie for an automated login (often used with forum
systems where 'Log me on automatically each visit' is used ). How do they
deal with this limitation?

regards
Stijn

kind regards
Stijn
Jul 16 '05 #3
(dolphin talk) eeeeeekkkkkk squueeeekkkkk Stijn Goris eeeeeiiiiiiikkk kkkkk
squeeeeekk Fri, 12 Sep 2003 20:02:59 -0500, eeeeeiiiiiiieee eeekkkk
eeeeekkkkkk eeiiikkkk <3f************ **********@read er2.news.skynet .be>:

----- Original Message -----
From: "Randell D." <yo************ **************@ yahoo.com> Newsgroups:
comp.lang.php
Sent: Friday, September 12, 2003 10:42 PM Subject: Re: beginner cookie
think
"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************** @reader1.news.s kynet.be...
> hi all,
>
> Trying to get those cookies to work but they wont...
> [...]
>

Your problem is likely due to a limitation to cookies, not php.

A refresh has to have occured before your cookie becomes available to
your environment
[...]

Hi,

Thanks for your reply. Indeed, when I refresh the page where the cookie
is defined, the cookievariable is set. What is the best way to overcome
this cookie limitation? [...]


Hi Stijn

To overcome the need to refresh, set the cookie's value
in *both* the HTTP response header and the $_COOKIE array
at the same time:

$_COOKIE['mycookie'] = 'chocolate chip';
setcookie('myco okie', $_COOKIE['mycookie']);

If you synchronize the HTTP response and the $_COOKIE
array on the first page that sets the cookie, you won't
have to refresh.

HTH

This message is under the GPL.

Jul 16 '05 #4

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

Similar topics

6
2197
by: Ajay | last post by:
hi! i am printing a simple cookie, but instead of printing um=name:blah&access:admin&exp:2312390.909 its printing um="name:blah&access:admin&exp:2312390.909" why the quotes?
18
8845
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page (same folder). The cookie is not received. Can someone explain why? I worked around this by adding a cache-control header with a value of no-cache. This fixes the problem. Unfortunately that causes another problem with Internet Explorer...
4
5295
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a cookie. Here is the code I have now. In the header, I have the following: <SCRIPT language="JavaScript"> var cookieStatus; if (document.cookie.length > 0) { cookieStatus = 'Cookie exists with value ' + document.cookie; } else {
2
1615
by: marshalli | last post by:
Hi: I have a problem with writing cookie from Jacascript. My problem is that I have two server, one is A, and the other is B. (1) I call a aaa.html from A. In aaa.html : ... <iframe id="frame1" src='http://B/bbb.html'></iframe> ... (2) In bbb.html :
17
4177
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page hosted at two.com If I view the frameset from one.com in Firefox, all works well with the content from two.com. But if trying to view this using IE (with standard security settings), the cookie set by two.com is not accessible.
5
5918
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, Is there an easier way to handle that? I used Javascript to handle this when our two domains are hosted on two different servers(on different networks) and our search engine marketing people don't like the javascript links since they think the links are not favorable to a search robot. Now our company is thinking about hosting these two domians on the same server, So I am wodering if there is any easy way to do that. Would you...
5
3161
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in my HTTP header but do not get anything in the cookie text file. I'm working on linux. print "Content-type: text/html" cookie = Cookie.SimpleCookie()
16
2979
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but something that PHP guys would know the answer to. I can't think of a more appropriate forum to try. I've heard the ASP and JSP guys aren't as friendly ;-) Let's say we have a HTML page from domain example.com, and that HTML page makes a request to...
0
8888
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8097
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.