0

I am trying to use PHP in an HTML page to change Login to Logout and reference my login page. Instead of printing 'Login' and 'Logout' I get the following: Logout" ; } else { echo" Login" ; } ?>

The IF function seems to get confused and starts echoing Logout when it should not start until Login. My code is for the last selection on an html line

<?PHP
if ("$login_successful" == "1") {
echo"<a href='http://www.icselect.com/login.php?logout=1'> Logout</a>" ;
}
else { 
echo"<a href='http://www.icselect.com/login.php'> Login</a>" ;
}
?>

Any suggestions are welcome.

8
Contributors
15
Replies
16
Views
7 Years
Discussion Span
Last Post by vaultdweller123
0

try changing "$login_successful" == "1" to $login_successful == 1

if ("$login_successful" == "1") {
0

op has searched for a literal 1 (number) not for a true boolean

that's true

op might want to try this the meta eqiv = is a much faster and nicer way too, depending on what's
required and if it's a php server self.

<?php if($login_successful == "true") { echo "<a href='http://www.icselect.com/login.php?logout=1'> Logout</a>"; }

      else { echo '<meta http-equiv="refresh" content="2;url=login.php">'; }
?>

Edited by harry_watson: Suggestion

0

As simple as it sounds, Your code [what you have at the moment on the page] is correct, but you should name your script from ics2_design.html to ics2_design.php OR you should make your apache parse html files as php.
If you view the source of the page, you will see that the php code in the page isn't parsed.

:) Cheers!

0

Sorry everyone. I still get
Logout"; } else { echo " Login"; } ?>
except for harry's suggestion which doesn't print Login.
You can see this at http://www.icselect.com/ics2_design.html

If the user is logged in successfully then set the variable login_successful to 1 as I shown in the below code

$login_successful = 1;
if ($login_successful == 1) {
echo"<a href='http://www.icselect.com/login.php?logout=1'> Logout</a>" ;
}
else { 
echo"<a href='http://www.icselect.com/login.php'> Login</a>" ;
}
0

there's no problem with the code... i don't think the problem came there... it might be the code before that. Try reviewing your code.

0

The problem was no in the ($login_successful == 1) test but in the faulty printing to the screen. I will just use two different templates.

Thanks everyone

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.