Re: newbie simple problem with cookie



In message <85vWf.38278$u31.10281@xxxxxxxxxxxxxxxxxxxx>, David Graham <david.graham18@xxxxxxxxxxxx> writes

Why does my cookie not get set?
I just get "Your last visit was - " and nothing else

<?php
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);
?>

setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);

should be:

setcookie("lastVisit", date("G:i - m/d/y"), $inTwoMonths);

Note the quotes around "lastVisited."

Also, cookies must be sent to the browser before any other output. The PHP manual says:

"Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace."
--
Martin Jay
.



Relevant Pages

  • Re: [Full-Disclosure] Exploits in websites due to buggy input validation where mozilla is at fault a
    ... >reason to disable javascript and never use cookies for authentication. ... cross-site scripting attacks. ... could allow improper nesting to get around improper code ... it tries to fix the tags stating that the page contains potentially ...
    (Full-Disclosure)
  • Re: WOT: McCain Political Ads
    ... problems, and one who was beaten with a baseball bat to his head, and ... left for dead. ... It's all the drugs & cookies that prevent a good beating. ... The first sign of insanity is denying that you're crazy. ...
    (sci.electronics.design)
  • Im off to Montana!
    ... The cookies will be Wyoming Whoppers, ... the Fly Trap, a restaurant in Ferndale, Michigan. ... From there I will head up to Glen Arbor and camp at Sleeping ...
    (rec.food.cooking)
  • Re: I want to keep the tags post html on
    ... Lets say that I have a script with the inputs ... Is there a way, that next time any user enters this page, the tags ... This is coming from the browser, so the browser has to remember them. ... An alternative would be to use cookies, and if the parameters do not exist, look for the cookie. ...
    (comp.lang.php)
  • Re: I want to keep the tags post html on
    ... Lets say that I have a script with the inputs ... Is there a way, that next time any user enters this page, the tags ... This is coming from the browser, so the browser has to remember them. ... An alternative would be to use cookies, and if the parameters do not ...
    (comp.lang.php)