473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Cookies are driving me nuts!

Hi.

This is probably a newbie cookie problem:

I got two files

setcookie.php:

<?
setcookie("cookie1","HELLO WORLD 1",time()+3600);
setcookie("cookie2","HELLO WORLD 2",time()+3600);
?>

and showcookie.php:

<?
echo $_COOKIE["cookie1"]."<br>";
echo $_COOKIE["cookie2"]."<br>";
?>

The result of running setcookie.php and then showcookie.php is:

Notice: Undefined index: cookie1 in C:\Apache
Group\Apache2\htdocs\showcookie.php on line 5

HELLO WORLD 2.
In other words, only the last cookie has been set. What is wrong? This
example is so simple, but yet I don't understand what is happening.

I'm running PHP 4.2.2/Apache 2.0.39 on Win2000.

Cheers

Kasper
Jul 17 '05 #1
8 1665
Kasper Kristensen wrote:
This is probably a newbie cookie problem:

I got two files

setcookie.php:
1 <?
2 setcookie("cookie1","HELLO WORLD 1",time()+3600);
3 setcookie("cookie2","HELLO WORLD 2",time()+3600);
4 ?>
and showcookie.php:
1 <?
2 echo $_COOKIE["cookie1"]."<br>";
3 echo $_COOKIE["cookie2"]."<br>";
4 ?>
The result of running setcookie.php and then showcookie.php is:

Notice: Undefined index: cookie1 in C:\Apache
Group\Apache2\htdocs\showcookie.php on line 5


line 5? ???

These scripts work for me as you've posted them.
I guess the error may be hidden on one of the lines you didn't post.

Turn on error_reporting for all errors in your scripts (at least while
debugging) by putting at the very top of them

<?php error_reporting(E_ALL); ?>

This is line 1, right before your opening <?php or <html> or whatever.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c2*************@ID-203069.news.uni-berlin.de...
These scripts work for me as you've posted them. I guess the error may be hidden on one of the lines you didn't post.


These are the only lines. I'm suspecting some kind og setup problem. Maybe
in httpd.config er php.ini.
Turn on error_reporting for all errors in your scripts (at least while
debugging) by putting at the very top of them

<?php error_reporting(E_ALL); ?>


I'll try that, and get back to you.

Cheers
Kasper
Jul 17 '05 #3

"Kasper Kristensen" <no****@nospam.invalid> wrote in message
news:40*********************@dread12.news.tele.dk. ..

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c2*************@ID-203069.news.uni-berlin.de...
These scripts work for me as you've posted them.

I guess the error may be hidden on one of the lines you didn't post.


These are the only lines. I'm suspecting some kind og setup problem. Maybe
in httpd.config er php.ini.
Turn on error_reporting for all errors in your scripts (at least while
debugging) by putting at the very top of them

<?php error_reporting(E_ALL); ?>


I'll try that, and get back to you.

Cheers
Kasper


Nope. Didn't explain a thing.

Kasper
Jul 17 '05 #4
Try making sure you have no spaces or carriage returns anywhere after line
4.
"Kasper Kristensen" <no****@nospam.invalid> wrote in message
news:40*********************@dread12.news.tele.dk. ..

"Kasper Kristensen" <no****@nospam.invalid> wrote in message
news:40*********************@dread12.news.tele.dk. ..

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c2*************@ID-203069.news.uni-berlin.de...
> These scripts work for me as you've posted them.
I guess the error may be hidden on one of the lines you didn't post.


These are the only lines. I'm suspecting some kind og setup problem. Maybe in httpd.config er php.ini.
Turn on error_reporting for all errors in your scripts (at least while
debugging) by putting at the very top of them

<?php error_reporting(E_ALL); ?>


I'll try that, and get back to you.

Cheers
Kasper


Nope. Didn't explain a thing.

Kasper

Jul 17 '05 #5
Kasper Kristensen wrote:
"Kasper Kristensen" <no****@nospam.invalid> wrote in message
news:40*********************@dread12.news.tele.dk. ..
"Pedro Graca" <he****@hotpop.com> wrote in message
news:c2*************@ID-203069.news.uni-berlin.de...
These scripts work for me as you've posted them.

I guess the error may be hidden on one of the lines you didn't post.


These are the only lines. I'm suspecting some kind og setup problem. Maybe
in httpd.config er php.ini.

Turn on error_reporting for all errors in your scripts (at least while
debugging) by putting at the very top of them

<?php error_reporting(E_ALL); ?>

I'll try that, and get back to you.

Cheers
Kasper

Nope. Didn't explain a thing.

Kasper


It looks like you are making the assumption that the first cookie is not
set - It just seems to have problems displaying it - I don't know why
(it works fine on my system) but what you could do is change your
showcookie.php script to what I have below - Alternatively, just change
showcookie.php to have a single command: phpinfo(); This command dumps
the full php environment out in a nice table so you should be able to
page down (or do a find on the page) for COOKIE1 and COOKIE2.

If you still have problems, just humour me and choose different names
for the cookies - Call COOKIE1 abc and call COOKIE2 def - It could be
that somehow, COOKIE1 is a reserved word and that cannot be used as an
index on your system.... I'm just pulling at straws here mind...
anyway... My suggested showcookie.php:

<?
foreach($_COOKIE as $cookieName=>$cookieValue)
{ print("<br>Cookie named $cookieName has value $cookieValue");
}
?>
Drop another byte if you still have problems...

randelld
Jul 17 '05 #6

"Peter Taurins" <DO*************************************@bigpond.c om> wrote
in message news:AY*******************@news-server.bigpond.net.au...
Try making sure you have no spaces or carriage returns anywhere after line
4.


No, that wasn't it. I also guess that this would result in the "header
already sent" error.

Kasper
Jul 17 '05 #7

"Reply Via Newsgroup" <re****************@please.com> wrote in message
news:U3x4c.789583$X%5.225024@pd7tw2no...
It looks like you are making the assumption that the first cookie is not
set - It just seems to have problems displaying it - I don't know why
(it works fine on my system) but what you could do is change your
showcookie.php script to what I have below - Alternatively, just change
showcookie.php to have a single command: phpinfo(); This command dumps
the full php environment out in a nice table so you should be able to
page down (or do a find on the page) for COOKIE1 and COOKIE2.

Yep already tried that. "cookie1" is not set. Actually if I extend it to
"cookie1","cookie2"..."cookieN" only "cookieN" gets set.

If you still have problems, just humour me and choose different names
for the cookies - Call COOKIE1 abc and call COOKIE2 def - It could be
that somehow, COOKIE1 is a reserved word and that cannot be used as an
index on your system.... I'm just pulling at straws here mind...


No doesn't work work either. The last cookie is the only one that is set.

Cheers
Kasper
Jul 17 '05 #8
No doesn't work work either. The last cookie is the only one that is set.

Cheers
Kasper


Just found at that it works under PHP4.3.4, which my web hotel runs, so I'll
try to upgrade.

Thanks for your suggestions.
Kasper
Jul 17 '05 #9

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

Similar topics

7
by: Fnark | last post by:
Can anyone tell me why this code does not do what I want it to: <?php if (!isset($_COOKIE)) { setcookie("basket", $item_code, time()+60*60*24*30, "coursework", '', 0) ; } else { setcookie(...
6
by: Keiron Waites | last post by:
Please see the problem in action here: http://www.leadbullet.biz/contact.php If you mouse over the fields, you will see that text is shown on the right. The text makes the other fields move when...
12
by: Marty | last post by:
It seems all of the sudden that user controls that contain images are referencing image sources relative to the document that I drop the control on. This obviously does not work beacuase the...
0
by: Simon Harris | last post by:
Ok, this really is driving me nuts!!! :( 'All' I am trying to do is get the value of a named element. My XML doc is: <?xml version="1.0" encoding="utf-16" standalone="yes" ?> - <Page>...
4
by: trond | last post by:
Hello all, Before I start I'd like to point out that I am a complete novice when it comes to asp.net - My background is in network and operating systems, and although I have been doing a bit of...
2
by: mitsura | last post by:
Hi, I need to read a simle XML file. For this I use the SAX parser. So far so good. The XML file consist out of number of "Service" object with each object a set of attributes. I read...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
3
by: DuncanIdaho | last post by:
Hello experts IE 7.0.5730.11 Opera 9.27 Firefox 2.0.0.14 This problem only occurs in Opera and Firefox (amazing, IE does something right, or maybe not) Anyway, the problem is that when I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.