Jump to content

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.

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.