Jump to content

Log out Problem


enemeth

Recommended Posts

Hi there :)

 

got this problem with the log out script, can someone tell me what i am doing wrong?

 

<?php
    // This blurb starts the session for the users.
    session_start();
    header("Cache-control: private"); // Fix for ie6

?>
<?php 
$msg = "Please Log In!"; ?>
<?php   
if(!isset($_SESSION['username']))  
{    
echo("<meta http-equiv='Refresh' content='0; URL=../login.php'/>");
echo ("<script langauge=\"javascript\">alert(\"".$msg."\");</script>");
}
else {
?>
<?php include("headermem.php"); ?>
<center><font color=white> Are you sure you want to logout?</font></center><br> 
<center><a href=/index.php>Yes</a> | <?php unset($_SESSION['username']); ?>

<a href=javascript:history.back()>No</a>"; 
<?php include 'footermem.php'; ?>
<?
}
?>

 

i guess you guys can see it right off the bat ! but i guess i am blind ;)

 

but everytime you go to the page it logs you out no matter what your choice is

 

Thank you

 

Elaine

 

Link to comment
Share on other sites

Try this:

<?php include("headermem.php"); ?>
<center><font color=white> Are you sure you want to logout?</font></center><br> 
<center><a href=/logout.php>Yes</a>

 

Create a new script and name it logout.php

session_start();
  $_SESSION['username'];   // store  to test if they *were* logged i

if (!empty($_SESSION['usename']))
{
  if (isset($_SESSION['username']))
  {
    unset($_SESSION['username']); 
    session_destroy();
    echo "Logged out.<br>";
  }
  else
  {
   // they were logged in and could not be logged out
    echo "Could not log you out.<br>";
  }
}
else
{
  // if they weren't logged in but came to this page somehow
  echo "You were not logged in, and so have not been logged out.<br>";
}

 

Link to comment
Share on other sites

<?php
    // This blurb starts the session for the users.
    session_start();
    header("Cache-control: private"); // Fix for ie6

?>
<?php 
$msg = "Please Log In!"; ?>
<?php   
if($_SESSION['username']==NULL)  
{    
header("location: ../login.php");
echo ("<script langauge=\"javascript\">alert(\"".$msg."\");</script>");
}
else {
include("headermem.php"); ?>
<center><font color=white> Are you sure you want to logout?</font></center><br> 
<center><a href=/index.php>Yes</a> | <?php unset($_SESSION['username']); ?>

<a href=javascript:history.back()>No</a>"; 
<?php include 'footermem.php'; 
}
?>

 

try that

 

edit:

if you want to make a logout page array $_SESSION['username']

Link to comment
Share on other sites

Ok guys,

 

i cant figure it out i have been playing with this code for a while now , cant seem to get it to work

 

can someone help me get it to do this :

 

log out button get clicked , goes to a page that will give you the choice , yes or no to log out or not to log out

if the user hits yes he is notified that he is now logged out , and then redirected to the index.php page of the site !

 

thanks a million ;)

 

Elaine

 

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.