Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions not ending 1

Status
Not open for further replies.

andy98

Programmer
Jul 7, 2000
120
GB
Hi

I have just today started to look into PHP sessions and have created my LOGIN page. But when I LOGOUT and close the browser. I can still open a new browser window and bypass the LOGIN page and access other parts of my application.

When I login I set the following variable:
Code:
$_SESSION['Logged_In'] = "True";

In my logout I am doing this:
Code:
<?
session_start(); 
header("Cache-control: private"); //IE 6 Fix 
session_unregister('Logged_In');
$_SESSION['Logged_In'] = False;
$_SESSION['s_password'] = False;

$_SESSION = array(); 
session_destroy(); 

    // Redirect to show results.. 
echo "<script>document.location.href='index.php'</script>";

?>


And the top of the page I access afterwards - to see if it will kick me out - I have this - And this is where I think it must be wrong - but I cannot see it! It bypasses this code and runs the page! Any help greatly appreciated!

Code:
<?php 
session_start(); 
if ($_SESSION['Logged_In'] = FALSE) 

{
echo "<script>document.location.href='index.php'</script>";
}


 
Are you closing all your open browsers or just the one that you were viewing the site with? All the open browsers should be closed. And if you close all the open browsers, it won't destroy the session on the server, but it will end it from your machine.

Rick

 
Yes - i am closing all browser sessions. I'm convinced it must be in the page that I later try to access because I test for a session variable when I go back to the index.php page an it is blank - but when I try the URL to a specific page with this code at the top of the page:
Code:
<?php 
session_start(); 
if ($_SESSION['Logged_In'] = FALSE) 

{
echo "<script>document.location.href='index.php'</script>";
}

it doesn't go back to the index.php page like I am expecting it to do!

I can't see where I am going wrong!

 
Try this:

Code:
<?
session_start();
header("Cache-control: private"); //IE 6 Fix
$_SESSION['Logged_In'] = False;
$_SESSION['s_password'] = False;

$_SESSION = array();

    // Redirect to show results..
echo "<script>document.location.href='index.php'</script>";

See if that does what you want.

Rick

 
Your problem is in this line:

if ($_SESSION['Logged_In'] = FALSE)

you're using the assignment operator, not the comparison operator. The line should read:

if ($_SESSION['Logged_In'] [red]==[/red] FALSE)

In the case of using the assignment operator in an if-clause, the assignment returns whatever is assigned. In this case, FALSE, so the statement in the clause is never run.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I've made that mistake so many times. It's usually the smallest errors that cause so much frustration, just because they're so hard to notice after you've been staring at the code for very long.

Rick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top