Welcome Guest, Not a member yet? Register   Sign In
if(!$_SESSION['username']) ?
#1

[eluser]whygod[/eluser]
I got these PHP codes somewhere
And I'm a little confused.

Code:
if(!$_SESSION['username'])
{
    include_once 'autologin.php';
}

Does it means if $_SESSION['username'] not empty it include autologin.php?

Please correct me if I'm wrong.

Thanks in advanced.

#2

[eluser]tpetrone[/eluser]
The way that reads is..

Code:
if(!$_SESSION['username'])

says .. If NOT TRUE


So if the $_SESSION['username'] is set to anything other than TRUE then the brackets are executed.
#3

[eluser]whygod[/eluser]
not true what?

How about in layman word?

If username is not in session?
or
If username does not exist in session?
#4

[eluser]tpetrone[/eluser]
not true what?

How about in layman word?

If username is not in session?

if(!$_SESSION['username']) in layman's terms.. if the array $_SESSION has a key called "username" and it's not set. But more specifically this it will act like a Boolean TRUE/FALSE.. So if $_SESSION['username'] is "FALSE" - identified by the "!" then run the autolgin.php .

or
If username does not exist in session?

That is another way to read it but the behavior of the execution is not what you would expect.

Cleaner way of doing this so that it reads a bit better.

again not knowing what the username should be set too.

Code:
if(isset($_SESSION['username']) && $_SESSION['username'] === TRUE )
{
  //.. Do something here...//

}else{

   include_once 'autologin.php';

}


Since you didn't post the full source not sure what you are attempting to achieve.

Hope this helps.
#5

[eluser]WanWizard[/eluser]
Perhaps you should read http://php.net/manual/en/types.comparisons.php to see how PHP evaluates variables.




Theme © iAndrew 2016 - Forum software by © MyBB