Jump to content

Recommended Posts

Hello guys,

 

i have a problem in logout module that when i click on the back button the session is not destroyed. i am using three functions like

  • session_start();
  • session_unset();
  • session_destroy();

 

on each page. Can anyone take me out of this

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/168984-handling-logout/
Share on other sites

I have used session_unset() and session_destroy() with much success. maybe post your code?

 

Edit: also make sure that on every member only page you have some sort of validation script running like

if (!isset($_SESSION['user'])){
##your not logged in message and maybe redirect
}

 

Link to comment
https://forums.phpfreaks.com/topic/168984-handling-logout/#findComment-891593
Share on other sites

Hello mikesta707,

 

this is the code that i have written for logout page.

 

<?php

session_start();

session_unset();

session_destroy();

if(!(isset($_SESSION['username'])))

{

header('Location: page1.php');

}

else

{

echo $_SESSION['username'];

echo $_SESSION['product1'];

}

echo "<a href='page1.php'>Logout</a>";

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/168984-handling-logout/#findComment-891606
Share on other sites

please have a look on these pages. when i click on the back button, this actually doesn't display page3.php but i think fetching it from cookies.

 

 

 

page1.php

 

<body>

<form action="page2.php" method="post">

    Name:<input type="text" name="username" value="" /><br />

    Pass:<input type="password" name="pwd" value="" /><br />

    <input type="submit" name="sbt" value="Submit" />

</form>

</body>

 

page2.php

<?php

 

    session_start();

    session_unset();

    session_destroy();

   

    $username=$_POST['username'];

    $_SESSION['username']=$username;

   

   

    if(!(isset($_SESSION['username'])))

    {

        header('Location: page1.php');

    }

 

    //$_SESSION['username']=$username;

   

    echo $_SESSION['username'];

    echo "<a href='page3.php'>page3</a>";

   

 

?>

 

page3.php

 

[/]<?php

    session_start();

    session_unset();

    session_destroy();

    if(!(isset($_SESSION['username'])))

    {

        header('Location: page1.php');

    }

    else

    {

        echo $_SESSION['username'];

        //echo $_SESSION['product1'];

    }

        echo "<a href='page1.php'>Logout</a>";

   

?>[/][/]

Link to comment
https://forums.phpfreaks.com/topic/168984-handling-logout/#findComment-891637
Share on other sites

Im not entirely sure what you mean by "this actually doesn't display page3.php but i think fetching it from cookies." but on page 2, you always set the session to something no matter what, so it will show you as logged in. change on page 2

 

$username=$_POST['username'];
    $_SESSION['username']=$username;

to

 

if (isset($P_POST['username'])){
$username=$_POST['username'];
$_SESSION['username']=$username;
}

 

that way you don't set the session even if the user didn't actually send a post request to log in. Also, you should have some sort of validation. With the current set up (assuming this is all the code you have) all anyone has to do to log in is type in a username.

Link to comment
https://forums.phpfreaks.com/topic/168984-handling-logout/#findComment-891642
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.