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.

Recommended Answers

All 15 Replies

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

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

Slammer,

Sorry but that did not work.

what about something like

if ($logged_in == 'true') {?>

ok not sure what else you've done. I was thinking of 'true' rather than '1'

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

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">'; }
?>

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!

your php is ending and becoming text here > Logout< you could try this...

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

<?php;}
else { echo "<a href='http://www.icselect.com/login.php'> Login</a>"; }?>

And Nav33 is right. give your file a .php extension. Maybe that's all you need to do.

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>" ;
}

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.

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

one way of saying thanks is marking this thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.