Jump to content

Recommended Posts

The below is constantly loading the password page no matter what is enter in the password input on the form (on another page). I have checked the $login variable by echoing it and it is carrying the value from the field.

 

<?php
$off="yes";
$login=$_POST['login'];
if($off=="yes" && (!isset($_SESSION['login']) || $_SESSION['login']!="pass")){
    if($login=="" || $_SESSION['login']!="pass"){
    header('Location: ./index2.html');
    exit();
    }
    elseif(!isset($_SESSION['login'])){
    session_start();
    $_SESSION['login']=$login;
    header('Location: ./index.php');
    exit();
    }
}
elseif($off=="no" || $_SESSION['login']=="pass"){
content goes here.
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/259696-log-in-if-statements/
Share on other sites

My first feeling is messy code. never write it all at once use a switch statement to check for posts it is cleaner, neater and will always get the job done.  If you have a session make sure you have not only started it

session_start();

but

registered it

session_register("user, pass"); ect.

deal with form data and session data in turn, not as a unit.

Can't use session_register... register_globals is turned off on my server.

 

And according to php.net

 

Caution

 

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered.

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.