Page 1 of 1

using href in php

Posted: Mon Sep 02, 2013 2:47 pm
by fjbanduk

Code: Select all

<? php
			$loggedin=true;
			if $loggedin
			{
			echo Hello Travelore. Not you?
			echo "<a class=\"item\" href=\"login_register.php\">Log out."
			}
			else
			{
				echo "<a class=\"item\" href=\"login_register.php\">Login / Register</a>"
			}
?>			
gives output as -
[text]
Log out." } else { echo "Login / Register" } ?>
[/text]
Tried a lot of options with single quote, double quote, with slash and without. But this just doesn't seem to work.

Re: using href in php

Posted: Mon Sep 02, 2013 2:52 pm
by Celauran
Lines must end with a semicolon.

Re: using href in php

Posted: Mon Sep 02, 2013 10:00 pm
by Christopher
And no space between <? and php in you opening PHP tag.

Re: using href in php

Posted: Tue Sep 03, 2013 1:05 am
by fjbanduk
Thanks. This worked. Here's the improved code.

Code: Select all

<?php
	if($_SESSION['signed_in'])
		{
		echo 'Hello <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="signout.php">Sign out</a>';
		}
	else
		{
		echo '<a class="item" href="signin.php">Sign in</a> or <a class="item" href="signup.php">create an account</a>';
		}
?>