x_wd11 Posted July 28, 2019 Share Posted July 28, 2019 Do I set the cookie first or session? <li><?php // Create a login/logout link: if ( (isset($_COOKIE['user_id'])) && (basename($_SERVER['PHP_SELF']) != 'logout.php') ) { if (isset($_SESSION['user_id'])) { echo '<a href="logout.php">Logout</a>'; } else { echo '<a href="login.php">Login</a>'; } } else { echo '<a href="login.php">Login</a>'; } ?></li> Or do I set the cookie at a later time? Also, there's a session call in login and then in loggedin, both files need to call for session start? I do not believe you say that anywhere in the chapter if both are required. Thanks Link to comment Share on other sites More sharing options...
Larry Posted July 29, 2019 Share Posted July 29, 2019 You shouldn't be storing the user_id in both a cookie and a session. Figure out which approach you ought to be using--cookies or sessions--and just go with that one. Link to comment Share on other sites More sharing options...
Recommended Posts