isset($_COOKIE['name'])) not working

Aditya Sastry picture Aditya Sastry · Jan 1, 2013 · Viewed 11.9k times · Source

So I am making a blog for myself and to give myself admin privileges I set a cookie. I have manually checked its existence.

And I have tested the code on my laptop using apache server and the code works fine.

I have two php pages

First one detects the cookie fine, I post onto this php page from a form.

<?php



if(isset($_POST['tt'])){

    if(isset($_COOKIE['name'])){
        echo "something";

something is printed

The above page is the only page that detects the cookie I have 7 more files none of them detects the cookie. I will post the main page here

    if(isset($_GET['cat'])){
    $t = $_GET['cat'];
    $mod = "where `cat`=$t";
}

    $ref = mysql_query("SELECT * FROM `content`".$mod);
    while($row = mysql_fetch_assoc($ref)){
        $tit = $row['title'];
        $cno= $row['cno'];
        $brief = $row['brief'];
        $cat = $row['cat'];
        $time = $row['time'];
        $t = "";
        if(isset($_COOKIE['name'])) echo "something";

the something is not printed

also 1)Except the first code segment, none of the other pages uses a post method and retrieves data prior to checking the cookie.The rest of the pages sometimes have a get method before the checking the cookie like I have shown above, but none uses a post method before checking the cookie 2)var_dump['$_COOKIE'] yields only unrelated cookies set by my hosting provider.

I guess this is a php configuration problem may be ?

Answer

Jan Schejbal picture Jan Schejbal · Jan 1, 2013

The cookie might be a path cookie, meaning that it will be sent only to one page. Use the Firebug "Cookies" tab (or similar tool) to check if this is the case, and use the Firebug "Network" tab (or similar tool, or Wireshark) to check if the cookie is actually sent by the browser.