0

my cookies not seem to be working. the seesion works fine tho. am i missing some thing?
o and i doesnt print echo"on";

                if($remember_p == "on")
                {
                    //remember username for 42 hrs
                    setcookie("id", $id, time()+20); 
                    setcookie("username", $username_p, time()+20); //seconds 
                    //header("location: index.php");    
                    if(isset($_COOKIE['username']))
                    {
                    echo"on";
                    }
                }
                else if($remember_p == "")
                {
                    //create session variables
                    $_SESSION["id"] = $id;
                    $_SESSION["username"] = $username_p;
                    header("location: index.php");  
                }
2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by LastMitch
4

@hwoarang69

Try this

var_dump($_COOKIE);

in here:

if(isset($_COOKIE['username']))
{
var_dump($_COOKIE);
}

to see whether dump the cookie stuff, and also why are you using $id? Is this unique_id? You should store it in store a unique id instead of id to protect people from hacking.

Edited by LastMitch: grammer

Votes + Comments
To Rectify what some retard did to LastMitch
0

i tried it and i get:
array(3) { ["id"]=> string(1) "1" ["username"]=> string(6) "person" ["PHPSESSID"]=> string(26) "fvvn7lflgchti7apsgcbeqd2u5" } on

so it seem to be getting the values. but it doesnt log me in.

2

That's looks right. So the cookie is working!

Did you make sure your php.ini file allows cookies?

0

o wow. thanks i got it what the problem is.

also

is it ok, if i only have seesion username? and just remove seesion id
bc if i have session username than i can use sql to see there id and other stuff

Edited by hwoarang69

2

if ok if i only have seesion username? and just remove seesion id
bc if i have session username than i can use sql to see there id and other stuff

That is weird question you ask. You want to remove the session id? Why? The id is in the DB and when you login it needs to fetch the data to confirm. Does that make sense.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.