user544079
user544079

Reputation: 16629

cookie not getting set

A very novice question. I am trying to set a cookie

<?php 
    $expire = time() + 24*60*60; //1 day limit
    setcookie("name","Foo", $expire);
    echo $_COOKIE["name"]; //nothing is displayed
    var_dump($_COOKIE["name"]); //returns NULL 
?>

I am sure it's something very trivial. Any suggestions?

Upvotes: 0

Views: 41

Answers (1)

Nick Andriopoulos
Nick Andriopoulos

Reputation: 10643

cookie will be available in your next page load. setcookie just queues it to be sent along with page headers. $_COOKIE array contains the cookies that arrives with the request.

Upvotes: 3

Related Questions