Logic problem with login page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yoji
Forum Commoner
Posts: 25
Joined: Sun Oct 19, 2008 3:09 am

Logic problem with login page

Post by yoji »

Ok this one is complicated... Not because I am a pro, but because I really messed the code up... I started making a personal diary project

just for the practice. I only made the login page when I decided to transfer my code to a good looking template. The problem with template is

that the login box is on the left side of main page...Here is what I want to do: I want the login box to dissapear whenever I login. I have

tried this approach, which btw doesn't work:

Code: Select all

 
if ($a=="true")
{
// login box disappear
}
else
{
// login box appear
}
 
The reason the code DOESN'T work is because the variable $a gets refreshed once I press the submit button of my login page, and when it does

gets refreshed $a loses its "true" value give to int earlier and it goes to the "else" part of loop... so no avail.

I have tried putting a switch statement too:

Code: Select all

 
Switch ($a)
{
    case "true":
    //login box disappear
    break;
    default:
    //login box appear
}
 
It does the same job. Now you might say that I may try putting a particular value for the variable to make the box appear like this :

Code: Select all

 
if ($a=="true")
{
// login box disappear
}
elseif ($a=="false")
{
// login box appear
}
 
But the problem with such statement is that the value in $a is NOT false... Suppose even If keep $a="true" in start of code but that will

cause the whole loop to NOT work everytime...
It is a logical problem... Can't figure out any way :dubious: ... If you guys need code I will be more than willing. I just didn't place it because It is quite confusing... Ask anything to get a clear picture.
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: Logic problem with login page

Post by Hannes2k »

Hi,
if the user is loged in, set a variable, e.g. $logedIn=true; (this had to be done on each site).
Then you have to make sure that your template engine can access this variable.

An other way is to check the session variable directly. If you login in, I guess you set a session variable (e.g. $_SESSION['userid']).
In the template engine, you have only to check if this session variable is set or not.
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Logic problem with login page

Post by oscardog »

Or an easier way would be to do something like.. well i dont know the exact code, but upon login set a cookie, then use the !is_cookie_registered or whatever and if it doesn't exist, put the code to put the form and if it does exist do echo ""

Simpler than the other idea.
Post Reply