Rectangle 27 0

<?php 
ob_start();
session_start();
session_destroy();
header('Location:login.php');
?>

session - PHP logout system not working. (session_destroy on MAMP) - S...

php session mamp logout
Rectangle 27 0

@tom.e.degroot: Last time I checked, "it didnt work" was not an error message. You'll need to describe the symptoms a little more. Please follow the guidance here: http://SSCCE.org and give us something we can install and test on our own servers. Thanks, ~Ray

Dear Ray, Thank you for your construtive comment. I am new here and I am glad you gave me this useful tip. When I tried what you suggested I got a 404 error from my browser (hence, not the 404 message generated by CodeIgniter. Is this a better description?

session - PHP logout system not working. (session_destroy on MAMP) - S...

php session mamp logout
Rectangle 27 0

<?
    session_start();

    $_SESSION = array();
    header("Location: index.php");
?>

session - PHP logout system not working. (session_destroy on MAMP) - S...

php session mamp logout
Rectangle 27 0

These are the essential parts of a logout, assuming that your scripts are using PHP sessions. Note that your logout script causes a parse error because it is missing semicolons at the end of statements. Maybe just a typo.

<?php // RAY_EE_logout.php
session_start();

// CLEAR THE INFORMATION FROM THE $_SESSION ARRAY
$_SESSION = array();

// IF THE SESSION IS KEPT IN COOKIE, FORCE SESSION COOKIE TO EXPIRE
if (isset($_COOKIE[session_name()]))
{
   $cookie_expires  = time() - date('Z') - 3600;
   setcookie(session_name(), '', $cookie_expires, '/');
}

// TELL PHP TO ELIMINATE THE SESSION
session_destroy();

// REDIRECT TO THE HOME PAGE
header("Location: /");
exit;

session - PHP logout system not working. (session_destroy on MAMP) - S...

php session mamp logout
Rectangle 27 0

If calling logout.php when it containts the code below does not print test then there is something else wrong and it has nothing to do with the sessions.

<?php 
echo 'test';
//session_start()
//session_destroy()
//header('Location:login.php');
?>

You mention that it still shows the index.php, which makes me thing you have a rewrite rule in your .htaccess file which redirects the call from logout.php to the index. Check your htaccess file for any rules.

You can find information about htaccess on MAMP here

Thank you for your answer. Unfortunately, I couldnt fix it. I have only one .htcacces file, not in my site root folder: Options -Indexes I just tested the following: I changed the link in my menu to logout1.php and also made a logout1.php file; both logout.php and logout1.php are located in the site root folder. In logout1.php I made a simple echo statement: <?php echo 'test'; ?> Still this file isnt reached. All my other links in the menu work without any problem. Under XAMPP there was also no problem. Do you have a suggestion to fix this?

You say it isnt reached. What do you see? 404 not found error or another page?

For some reason the logout1.php is now simply displayed. So I see the 'test' is echoed. If you look at my comment above it that now two problems occur: 1. When I go to logout.php by clikcing on the link the session info file is not destroyed (I see that in finder). 2. If I go type in the address manually the session info file is deleted after some seconds. 3. If I go back to index.php it first seems as if I am logged in. Then I refresh, and index.php looked as if I am logged out. Do you know a solution? (Thank you for your help so far!)

Addition: when I alter the link path in my menu.php from logout1.php to logout.php it takes quit some seconds before this is updated on the actual page (I do refresh after I have saved the changes). Maybe this info helps you.

And another addition: it seems that I only get the index.php for logged out people after I click the refresh button, thus: 1. Clicking on the link to the logout.php doesnt delete the session file; going there manually does delete the session file. 2. Then going back to index.php and clicking on a link to index.php then it still shows as if I am logged in. If i click refresh this changes.

session - PHP logout system not working. (session_destroy on MAMP) - S...

php session mamp logout