0

error:Notice: Undefined index: username in C:\xampp\htdocs\E_COMMERCE\INCLUDE\header.php on line 20

login in information:
so i have a checkbox called "$remember_p". if check box is on than i want to set cookies but if its not on than i want to set session.

if($remember_p == "on")
    {
        //cookies doesnt get destory when window is close
        setcookie("id", $id, time()+172800); 
        setcookie("username", $username_p, time()+172800); //seconds - 2 days 
        header("location: index.php");  
    }
    else if($remember_p == "")
    {
        //ession is destory if window is close
        $_SESSION["id"] = $id;
        $_SESSION["username"] = $username_p;
        header("location: index.php");  
    }

than in different file iam check if user in loged in or not:
in this line i get the error.

if((isset($_SESSION['username'])) || (isset($_COOKIE['username'])))  /*** user is loged in ***/

if user login with seesion than it work fine. but when user is log in by cookies than i get the error.

4
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
2

@hwoarang69

if user login with seesion than it work fine. but when user is log in by cookies than i get the error.

Try this

if( isset($_SESSION['username']) && $_SESSION['username'] == true  ) { 
  // This will let username get access granted by session
} else if( isset($_COOKIE['username']) && $_COOKIE['username'] == true  ) { 
  // This will let username get access granted by cookie
} else { 
  //if none of it works show error denied 
}
0

Try using -

if(isset("Provide the 'name' attribute of the checkbox here."))

instead of

if($remember_p == "on")

Then, provide the else part..

I think that should work

Edited by kbanerjee1: overlooked a certain section

0

Include more code if possible.

1) Show the form markup
2) The handling code (post pickup)
3) Have a look at your cookies within the browser - does it exist - or can you access it via php with some snippet (not the code above)?

This topic has been dead for over six months. 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.