Forum Moderators: coopster

Message Too Old, No Replies

session id problem

         

adamnichols45

11:57 am on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

can someone tell me why unset is not working please:

code on header.php is
----------------------------------------------

<?php
if ($_SESSION['auth']='true') {
echo "set";
$disp="logout";
}
else {
echo "not set";
$disp="Login";
}

?>

<a href="<?php echo $disp;?>.php" class="new2"><?php echo $disp;?></a>

-------------------------------------------------

on logout.php the code is

-------------------------------------------------
<?php session_start();
/*****
logout.php:
This file logs a user out.

/*
Logout script:
This is a very simple script that does the following:
Checks the user is already logged in.
Destroys/unsets all session data.
Redirects the user to their login page.
*/

// Log user out:
unset ($_SESSION['username']);
unset ($_SESSION['auth']);

// Redirect:
header("Location: index.php");
?>

---------------------------------------

So can someone tell me then why when it directs back to header.php the session[username] still prints "set"

Thanks for looking

orion_rus

12:42 pm on Jan 2, 2005 (gmt 0)

10+ Year Member



it seem's u redirect to index.php not to header.php
U need session_start() in a header.php i don't see it. It's too few code, to answer to your question.)
Try type some more)

adamnichols45

1:24 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



its not good haveing the session start in header.php because i am already calling it!

baze22

1:33 pm on Jan 2, 2005 (gmt 0)

10+ Year Member



Depending on your 'globals' setting you might also need to :

unset($auth);
unset($username);

baze

Birdman

2:34 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When doing a comparison, you need to use two equals signs, rather than one.

if ($_SESSION['auth'] == 'true') {

baze22

5:27 pm on Jan 2, 2005 (gmt 0)

10+ Year Member



if ($_SESSION['auth'] == 'true')

Oops. Missed that one. Also, if you want the $_SESSION['auth'] to be boolean, you'd need to leave off the quotes for the value TRUE.

Thinking about it, if $_SESSION['auth'] were boolean, you could just leave off the '== TRUE' altogether and just make it:

if ($_SESSION['auth']){

baze

adamnichols45

5:08 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for that - i have found that when i use the browsers back button my varibles look like they are all becoming corrupt.

go back a page and its full of errors such as these.

Notice: Undefined index: log in C:\Inetpub\wwwroot\aa\sell3.php on line 10

Notice: Undefined index: upfile in C:\Inetpub\wwwroot\aa\sell3.php on line 11

adamnichols45

8:35 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



also the page gives like the 404 error does any one know of a way i can bypass this so it automatically goes back to the last page and show no errors? thanks guys