Shivin narayan
Shivin narayan

Reputation: 45

can not retrieve a cookie value from echo $_COOKIE['name'] in php

setcookie(name, value, expire, path, domain, secure, httponly);

When I try to echo $_COOKIE['name'], it print a blank

Upvotes: 0

Views: 138

Answers (3)

Rizier123
Rizier123

Reputation: 59691

This should work for you:

<?php

    if(!isset($_COOKIE['action'])) {
        $cookie_value = "menuopen";
        setcookie("action", $cookie_value, time()+3600, "/", ".acvd.com");
    }

    if(!empty($_COOKIE['action']))
        echo $_COOKIE['action'];


?>

You have to look that your using the right name of the cookie also that acvd.com is your domain! And you can't have a secure connection but httponly!

Upvotes: 1

kamal kishore
kamal kishore

Reputation: 84

first Check the cookie name you have used during setcookie method You can also check your cookie value in browser following are the steps: 1 open debugger tool 2 go to resource tab 3 then go to cookies 4 then go to your domain name

there you will find the cookie name with corresponding value, check for your name is it there and what is the name whether it is name or action. if name then echo $_COOKIE['name'] if action then echo $_COOKIE['actionenter image description here']

Upvotes: 0

Tristup
Tristup

Reputation: 3663

<?php 
            $cookie_value = "menuopen"; 
            if(!empty($cookie_value))
            {
             setcookie("action", $cookie_value, time()+3600, "/", "acvd.com", 1, 1); ?>
           }

?>

I hope it will work for you.

Upvotes: 0

Related Questions