Jump to content

Recommended Posts

hey friends!

i have a website wherein users login to browse the other pages of the site.

on logout i want the pages to expire.

i have php coding

 

so on all the pages i have written

 

session_start()

 

at the beginning

 

 

and on click of logout hyperlink the logout.php file opens wherein i have written this code:

 

<?

  session_start();

  session_destroy();

  echo "U have been successfully logged out";

?>

 

but still on click of back button of the browser the pages are shown.

 

wht can be the pbm???

 

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

I'd set a session variable.

$_SESSION['userid']=$userid;

 

At the beginning of each "logged in" script check if that session variable exists. If not direct back to the login page:

<?php
if (empty($_SESSION['userid'])) {
  header("Location: login.php");
  exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273794
Share on other sites

You might want to destroy your sessions variables as well. Here's what I use to uber kill the session and its variables:

 

unset($_SESSION['username']);
unset($_SESSION['password']);
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}		
$_SESSION = NULL;
session_destroy();

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273814
Share on other sites

hello!

i tried the code u said.

but on click of back button of the browser i get this message

 

 

 

"  The page you are trying to view contains POSTDATA that has expired from cache. If you resend the data, any action the form carried out(such as a search or online purchase will be repeated. To resend the data, click OK. Otherwise, click Cancel.  "

 

when i click on OK i get the pages open and work very well.

 

 

i want the message to be displayed as "Page cannot be displayed"

 

 

wht should be done????

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273818
Share on other sites

hey,

This is the code i have written for my other pages after login

 

<?php

session_start();

include("config.php");

include("opendbs.php");

$username=$_SESSION['user'];

//$emailID=$_POST['username'];

//$password=$_POST['passwd'];

if(empty($_SESSION['user']))

{

  header("Location: index.php");

exit;

}

?>

 

 

 

and on the logout.php file i have written this code

 

<?

session_start();

unset($_SESSION['user']);

if (isset($_COOKIE[session_name()])) {

    setcookie(session_name(), '', time()-42000, '/');

}

$_SESSION = NULL;

session_destroy();

echo "You have been successfully logged out";

 

?>

 

 

still the pbm persists.

 

help?????????????

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273822
Share on other sites

Try this:

<?php
   session_start();
   unset($_SESSION['user']);
   if (isset($_COOKIE[session_name()])) {
       setcookie(session_name(), '', time()-42000, '/');
   }      
   $_SESSION = NULL;
   session_destroy();
   header("Location: login.php");
?>

 

If when you log the user out they're redirected to the login page it should be obvious to them they've been logged out.

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273827
Share on other sites

hey!

i tried the statement

 

          header("Location: index.php");

 

after session_destroy();

 

 

what i want is like how it displays in yahoo

session expired

or page cannot be displayed

 

tht way

 

but my pages open afer clicking on back button

 

 

help????????

 

Link to comment
https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273843
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.