St0ked56 Posted December 23, 2012 Share Posted December 23, 2012 Hello, This is probably an easy fix but I can't seem to figure out how to use the logout.php script to delete cookies. Doesn't work for me. However, I can create a quick php script to delete the cookies. Therefore the problem must lie in the logout script correct? Here is what I have (I have also downloaded Larry's script and tried that): <?php # Script 12.6 - logout.php // This page lets the user logout. // If no cookie is present, redirect the user: //if (!isset($_COOKIE['user_id'])) { // Need the function: // require ('includes/login_functions.inc.php'); // redirect_user(); //} else { // Delete the cookies: setcookie('user_id', '', time()-3600); setcookie('first_name', '', time()-3600); //} // Set the page title and include the HTML header: $page_title = 'Logged Out!'; include ('includes/header.html'); // Print a customized message: echo "<h1>Logged Out!</h1> <p>You are now logged out, {$_COOKIE['first_name']}!</p>"; include ('includes/footer.html'); ?> If the problem is not in this script which of the chapter 12 scripts should I be looking at? I know how to delete cookies and I have successfully done it but its driving crazy that the example is not working correctly. Any help would be greatly appreciated. Thank you and Happy Holidays! Mike Link to comment Share on other sites More sharing options...
Larry Posted December 26, 2012 Share Posted December 26, 2012 First, what browser(s) and OSes are you testing this on? Second, how do you know this script is not deleting the cookies? Link to comment Share on other sites More sharing options...
St0ked56 Posted December 26, 2012 Author Share Posted December 26, 2012 Hi, I am using Windows 7. Tested on Chrome and Mozilla. I know the cookies haven't been deleted because I check the cookies once I hit the logout button. They are still present. Also notice that the logout button doesn't change back to "Login". When I create a quick php script to delete the cookies only, I am able to delete them. I know they are deleted because they are no longer present in the cookies history. I am not able to get it working using the website template logging in and out. Its weird, I've checked each of the scripts associated with the logging in and out process and nothing seems to be different from the books. I want to try and figure this out so in the future if I run into this type of problem I can get a better idea of where to troubleshoot. Thanks for the response Link to comment Share on other sites More sharing options...
Larry Posted January 2, 2013 Share Posted January 2, 2013 I'm sorry, but I need clarification in order to best know what's going on. You say you check the cookies once you hit the logout button. How are you checking the cookies? What happens if you go into your browser and clear out all the cookies for the site, then use the system again? What differences are there between the code that's not working and the code you can get to work? Link to comment Share on other sites More sharing options...
Recommended Posts