Forum Moderators: coopster

Message Too Old, No Replies

cookie not getting set

unable to pass cookie

         

cneeds

7:10 pm on Oct 1, 2010 (gmt 0)

10+ Year Member



Hi

I'm setting a cookie at the top of fileA.php:

<?php
setcookie('client_internal_ID', $_GET['client_internal_ID'], 0, "/");

fileA.php calls fileB.php with:

<form name="AADform" method="post" id="userform" action="fileB.php">

When I retrieve 'client_internal_ID' from $_COOKIE it has a value that it was set to a few days ago. Does anybody have an idea of what I've broken?

Here is the code in fileB.php:

echo("client_internal_ID=".$_COOKIE['client_internal_ID']);

Chris

IanKelley

9:08 pm on Oct 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can't see anything wrong with the code you've posted. I would guess that $_GET['client_internal_ID'] is blank, therefore the cookie is being assigned no value.

cneeds

10:20 pm on Oct 1, 2010 (gmt 0)

10+ Year Member



Thanks Ian, that was my first reaction but I echo $_GET['client_internal_ID'] immediately after the setcookie and it's definitely populated...

Chris

cneeds

10:47 pm on Oct 1, 2010 (gmt 0)

10+ Year Member



Maybe it's a name thing? Can $_GET['client_internal_ID'] and $_COOKIE['client_internal_ID'] exist at the same time?

Chris

IanKelley

10:56 pm on Oct 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There isn't a conflict (that I'm aware of) with having the same variable name in both the _COOKIE and _GET arrays.

When you say that the value is the same as it was a few days ago... How is that possible when the cookie is set to expire at the end of the session?

Have you tried wiping your cookies and testing again?

cneeds

2:43 pm on Oct 2, 2010 (gmt 0)

10+ Year Member



ian asked: "
Have you tried wiping your cookies and testing again? "

Yup. I also don't know why it doesn't get cleat. Maybe a Firfox thing when it reloads the page after I restart the machine.

Strangely $_COOKIE['client_internal_ID'] always contains 5 in fileB.php

?

Chris

enigma1

2:56 pm on Oct 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what's the domain you setup for the pages? make sure it isn't localhost. Under win, use the hosts file and setup a test domain or use the local ips directly.

IanKelley

5:32 pm on Oct 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Strangely $_COOKIE['client_internal_ID'] always contains 5 in fileB.php


Always? So that would imply that your problem is not with cookies at all, but that the ID is being set to 5 before the cookie is set.

cneeds

7:49 pm on Oct 2, 2010 (gmt 0)

10+ Year Member



Thanks guys.

Yes, I think it is localhosts but I don't know how to "Under win, use the hosts file and setup a test domain or use the local ips directly".

But I've narrowed the problem down to Firefox. I can get it to work in IE 8 and IE 6. But no matter what I do Firefox says $_COOKIE['client_internal_ID'] = '5'.

Fortunately all my users are using IE (business community) so I can move forward. But I really need to solve this if only for future reference...

Chris

enigma1

9:23 pm on Oct 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



check the C:\WINDOWS\system32\drivers\etc folder for a hosts file. Edit it add a line

127.0.0.1 www.example.com

Save it -do not modify the other lines in the file- then in your browser access the script using:

http://www.example.com/script.php

where script.php is the file you want to access and put the path also if you have in a subfolder which I doubt based on the cookie path you posted but anyways:
http://www.example.com/path/script.php

See if the cookie works.

cneeds

3:28 pm on Oct 4, 2010 (gmt 0)

10+ Year Member



I found the problem.

I was unsetting the cookie with the unset command but that wasn't destroying the cookie so I had to setcookie("client_internal_ID","",time() - 60*60);
to really clear it!

Chris