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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.