Jump to content

if $_GET && $_SESSION not listening to me lol.


Zephyris

Recommended Posts

I'm trying to make a page with multiple $_GET situations

 

example if my user wants to log out, he clicks the loggout link which sends him to

user.php?v=dc

 

if($_GET['v']=="dc") { session_destroy(); exit; }

if(isset($_GET['v'])=="dc") { session_destroy(); exit; }

 

but it seems no matter where the user goes it destroys the session.

 

if($_GET['v']=="mail") { // show mail }

 

but instead it does what's in $_GET['v']=="dc"

 

	<?php
if(isset($_GET["v"])=="dc"){
	if($_SESSION[user]=='Guest'){
	echo "You are not logged in fool.";
	exit;
	}else{
	echo "Session closed!";
	session_destroy();
	}
}
?>

That above doesn't work, when I go elsewhere it still destroy the session... no matter if it's a guest or not. If I go to ($_GET['v']=="godknows") as a user and not a guest, it will destroy the session.

 

I get the strangest errors...

S.O.S

 

to me, your script is saying "if he's not a guest" -> log him out, and that's what happens to you, you're a user, so you're being logged out because you're not a guest.

 

== guest // I'm NOT a guest I'm a user, so I go down to the else part

 

else {

 

session_destroy();

 

}

 

Maybe I misunderstood your situation, but that's how I got it.

Are you actually setting $_SESSION['user']?

 

Try the following:

<?php

  if(isSet($_GET['v']) && $_GET['v'] == 'dc') {
    if(isSet($_SESSION['user'])) {
      if($_SESSION['user'] == 'Guest') {
        echo 'You are not logged in fool.';
      } else {
        echo "Session closed!";
      }
    } else {
      echo '$_SESSION[\'user\'] is not set!';
    }
  }

?>

 

Regards, PaulRyan.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.