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
Rabastan
Forum Newbie
Posts: 6 Joined: Thu May 24, 2012 12:14 pm
Post
by Rabastan » Mon Aug 27, 2012 9:39 pm
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
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Aug 27, 2012 10:14 pm
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');
}
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Aug 27, 2012 11:23 pm
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;
}
Rabastan
Forum Newbie
Posts: 6 Joined: Thu May 24, 2012 12:14 pm
Post
by Rabastan » Tue Aug 28, 2012 8:05 am
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
Live24x7
Forum Contributor
Posts: 194 Joined: Sat Nov 19, 2011 9:32 am
Post
by Live24x7 » Tue Aug 28, 2012 10:56 am
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