Page 1 of 1

PHP Code

Posted: Thu Oct 28, 2010 5:14 pm
by deelliiaa
I am new to this forum and very new to code in general. I have a code that hides a block of text if a user is not logged into our site:

if( !empty($_SESSION['user'])

what I need is a code that will hide a different block of text if a user IS logged in.

Any help would be appreciated...

Re: PHP Code

Posted: Thu Oct 28, 2010 7:21 pm
by Jonah Bron
The opposite of

Code: Select all

if( !empty($_SESSION['user']))
would be

Code: Select all

if( empty($_SESSION['user']))
The exclamation mark indicates "not" or "the opposite of".

Re: PHP Code

Posted: Thu Oct 28, 2010 8:35 pm
by mikosiko
or maybe make more sense (at least for me) :wink: :

Code: Select all

if( !empty($_SESSION['user'])) {
  // here the code that hide text block 1.... user logged
} else {
  // here the code that hide text block 2.... user not logged
}

Re: PHP Code

Posted: Fri Oct 29, 2010 10:41 am
by Jonah Bron
Yes, that works too... but they're not necessarily in the same place.