Jump to content

Recommended Posts

hello friends!

 

what code shall i write to logout from the site???

 

i have a website where i allow the users to access the webpages once they have login.

 

i want the users to logout on click of a logout hyperlink. if user tries to click on the back button of the browser after logging out it should display session expired.

 

 

i have written the code as

session_start();

in all the pages after login

 

 

and on click of logout hyperlink the logout.php page opens where the code written is

 

<?php

  session_start();

  unset($_SESSION['user']);

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

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

  }     

  $_SESSION = NULL;

  $_SESSION['user']=NULL;

  session_destroy();

  header("Location: index.php");

?>

 

 

 

can any1 help me in this????????

thank you

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

<?php
session_start();
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Logout Success</title>
</head>

<body>
<h1>You have successfully logged out of the system</h1>
</body>
</html>

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