Jump to content

[SOLVED] Log in script


fesan

Recommended Posts

Hi there.

 

I have a very simple php login script on my page. just to have some security on some pages.

 

The login works fine, it logs in and displays the password required pages as they should.

But I am adding a script that enables a menu that is invisible to normal users. but it is always shown.

It seams i cant log out. I know this has worked before. Can anyone help me to find the bugs?

 

So in the end of the login proses it makes these variables:

session_start();
$_SESSION["login"] = true;
$_SESSION["user"] = $usr;
$_SESSION["status"] = $status;

 

 

in top of my index page i have this code:

session_start();
if(isset($_GET['logut'])) {
$_SESSION['login'] = false;
unset($_SESSION["user"]);
unset($_SESSION["status"]);
}

 

 

and on the pages required by index.php that needs password, this code is on top:

session_start();
if(empty($_SESSION['login'])) {
echo "You are not logged in";
} else { ?> 
HTML
<?php } ?>

 

my admin menu looks like this for testing reasons:

<?php
if ($_SESSION['login'] = true){
if ($_SESSION["status"] = "a"){
echo "<div id='admin'>";
echo $_SESSION['login']. "<br>";
echo $_SESSION['logout']. "<br>";
echo $_SESSION['usr']. "<br>";
echo $_SESSION["status"];
echo "</div>";
}
}?>

 

The results for:

login = 1

logout =

usr =

status = a

 

My logout link looks like this:

<a href='index.php?logut=true'>Log out</a>

 

Thanks for any help!!!

Link to comment
Share on other sites

didnt look very carefully to the code but i did notice this line:

 

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

 

You are initializing it, not comparing. Intending to compare you must use identical operator '=='.

 

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

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.