Jump to content

logout?


techker

Recommended Posts

well it is on the top of every page for security..

 

and the destroy will be a button on the main page to.

 

with this

<?php 

if(isset($submit)) 
{ 
session_destroy(); 
} 

?> 



is there a way to fetch the username?

i was thinking to grab it from myusername

session_start();
if(!session_is_registered(myusername)){
header("location:index.php");

session_destroy();
}

 

 

Link to comment
Share on other sites

Session_destroy() just deletes the session data file. Any $_SESSION variables in the current script will cause the session data file to be recreated with those value in it when the script ends.

 

All the various code to unset session variables, destroy sessions, and unset the session cookie is wasted processing time and wasted bandwidth. The simplest code, which is also the most reliable way of logging someone out, is to just have a logged in/logged out column in your user table in your database and just set the value to the logged out state.

Link to comment
Share on other sites

The following link contains some posts listing other advantages of just using a cookie/session to identify the visitor, but using value(s) stored in the user table to decide what they can do - http://www.phpfreaks.com/forums/index.php/topic,221684.0.html

 

Short version - even if someone is logged out, you can still keep the information that identifies who they are. And what if the session holds a language setting, do you want a multi-language web site to change to a default language just because someone logs out and you have unset/destroyed the session?

Link to comment
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.