using href in php

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

Post Reply
fjbanduk
Forum Newbie
Posts: 2
Joined: Mon Sep 02, 2013 2:36 pm

using href in php

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: using href in php

Post by Celauran »

Lines must end with a semicolon.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: using href in php

Post by Christopher »

And no space between <? and php in you opening PHP tag.
(#10850)
fjbanduk
Forum Newbie
Posts: 2
Joined: Mon Sep 02, 2013 2:36 pm

Re: using href in php

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