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.

Member Avatar for LastMitch

@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 
}

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

Member Avatar for diafol

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)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.