Closed Thread Icon

Topic awaiting preservation: Showing Cookies With PHP (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21819" title="Pages that link to Topic awaiting preservation: Showing Cookies With PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Showing Cookies With PHP <span class="small">(Page 1 of 1)</span>\

 
chris_ensell
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2004

posted posted 05-17-2004 06:20

Ok, I have a shoutbox at my site, www.ensellitis.com, and I am trying to get it to where if you have cookies enabled it shows a check box to save thier info if they want, and if they don't, it simply says
"Cookies are Disabled
Enable them to Save"
But for some reason, the snipplet I have is only saying cookies are disabled...
Here is what I have there now:

code:
<? 
if ($MODE!=="test") {
SetCookie("COOKIE", "VALUE");
Header("Location: ".$SCRIPT_NAME."?MODE=test");
exit;
} else if ($COOKIE=="VALUE") {
echo "<input type='checkbox' name='timer' value='1' style='border-style: solid' onclick='if(cc.interval)cc.stop();else cc.start();' class='main' checked /> <b><label>save info</label></b></font></td>";
} else {
echo "Cookies are disabled";
}
?>


I have done ok with the ShoutBox, until I got to this little tiny code...

If anyone can help my out, it would be much appreciated...

We're affraid to call it sex, so let's call it swimming...

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-17-2004 08:47

well... how would that ever work?
a) you shouldn't be using globals. THat's $_COOKIES['cookie'], not $COOKIE
b) you will never see the cookie, because it immediatly expires, you need to set a path, and a expiry time for it to reliabily work - even if those parameters are 'optional'
c) calling setCookie will not set the variable within $_COOKIES of the current script - but you're not trying to do that, anyhow.

so long,

->Tyberius Prime

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 05-20-2004 00:50

and the first line should read:

code:
if ($MODE != "test") {


Note the change from !== to !=

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio - Vim Tutorial -

(Edited by Veneficuz on 05-20-2004 00:51)

synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 05-20-2004 03:47

Veneficuz, I believe '!==' is valid. Though the latter would work as well.

"Nothin' like a pro-stabbin' from a pro." -Weadah

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 05-20-2004 07:32

Tyberius Prime:

when I set a cookie without specifiying an expiration, it lasts as long as the browser session. And the reference books I have all list this as the default behavior.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-20-2004 11:44
quote:
when I set a cookie without specifiying an expiration, it lasts as long as the browser session.


I've seen browsers do otherwise, no matter what the reference manual and the rfc says about it.

Hebedee
Paranoid (IV) Inmate

From: Maryland, USA
Insane since: Jan 2001

posted posted 05-25-2004 22:08

!== Means it's not exactly equal, if I recall correctly.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-26-2004 06:50

$a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only)
$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only)

Please read the docs instead of posting inaccurete things like that.

phoenix09
Neurotic (0) Inmate
Newly admitted

From: the pit... deep in the pit
Insane since: May 2004

posted posted 05-30-2004 23:41

I was hoping to find an answer to the same question, guess not. But here's one way to get your check box working, set the cookie with php, then test for that cookie with javascript on the page, that works fine, if the cookie is present, write your checkbox with javascript, if it isn't, write your cookie enabling message

why bother, when the power goes out it all goes away anyway...

by the way, thank god for firefox's web developer tool bar that lets you turn off site colors, otherwise I'd never be able to read this site...

(Edited by phoenix09 on 05-30-2004 23:43)

« BackwardsOnwards »

Show Forum Drop Down Menu