Jump to content

[SOLVED] Sessions not working...


pugboy

Recommended Posts

For some reason, the code below doesn't work when I navigate to index.php?do=setsession

 

It seems that the session is not being set, or something weird...

 

<?php
$do = $_GET["do"];
$type = $_POST["type"];
$user = $_SESSION["user"];
if(!$user=="admin"){
echo "LOGGED OUT";
}
if($do=="setsession"){
session_start();
$_SESSION["user"] = "admin";
}
?>

 

Is there something wrong with my code?

Link to comment
https://forums.phpfreaks.com/topic/109087-solved-sessions-not-working/
Share on other sites

okay because now you moved your $do assignment below your condition so $do will never equal setsession and you still have session_start inside the condition which will always fail now, so $user will never be assigned your session variable.

 

just put your code back to the way it was before, except move the session_start out of the condition to the top of your page.

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.