Page 1 of 1

If do nothing

Posted: Mon Aug 27, 2012 9:39 pm
by Rabastan
how would i actually make this work??

Code: Select all

if($login->isLoggedIn())
   "do nothing"
else
  header('location: admin_log.php');
meaning i want it to do nothing if its logged in

Rab

Re: If do nothing

Posted: Mon Aug 27, 2012 10:14 pm
by Benjamin
First, start using braces.

Code: Select all

if($login->isLoggedIn()) {

} else {
    header('location: admin_log.php');
}
Second, negate the condition with an !:

Code: Select all

if(!$login->isLoggedIn()) {
    header('location: admin_log.php');
}
Third, header redirects require an absolute path:

Code: Select all

if(!$login->isLoggedIn()) {
    header('Location: http://domain.com/admin_log.php');
}

Re: If do nothing

Posted: Mon Aug 27, 2012 11:23 pm
by requinix
And fourth, a header() redirect won't terminate your script - it will keep running. Assuming you don't want that, exit; or die; immediately after.

Code: Select all

if(!$login->isLoggedIn()) {
    header('Location: http://domain.com/admin_log.php');
    exit;
}

Re: If do nothing

Posted: Tue Aug 28, 2012 8:05 am
by Rabastan
First of all, Thank you both for your help. I am rather new to all this, would you please explain what you meant by "Start using braces"? If I am doing something wrong I would like to fix it.

Rab

Re: If do nothing

Posted: Tue Aug 28, 2012 10:56 am
by Live24x7
start using braces means use curly braces

Code: Select all

if () 
{
//this within curly brace
}

else
{
this within curly brace
}
you have ommited the curly brace in your code