Jump to content

php not playing nice with HTML


m.huber614

Recommended Posts

I'm trying to add a log in check that displays a link to log in or log out depending on whether the user is logged in or logged out.My PHP:<? phpif (session_is_registered('username'))then echo '<a href="saleslogout.php">Log Out</a>';else echo '<a href="saleslogin.php">Log In</a>';?>What I'm getting:Log Out'; else echo 'Log In'; ?>Where "Log In" is a legitimate link and "Log Out" is just plain text.I can't figure out what is going wrong. Any suggestions? I'd really appreciate it.

Link to comment
Share on other sites

This looks more like BASIC than PHP. And session_is_registered() is deprecated. Use the $_SESSION array.Try this:

<? phpif (isset($_SESSION['username'])) {  echo '<a href="saleslogout.php">Log Out</a>';} else {  echo '<a href="saleslogin.php">Log In</a>';}?>

Link to comment
Share on other sites

Same issue as before with the exception of now it reflects the new code:Log Out';} else{ echo 'Log In';} ?>I'm using Dreamweaver cs5.5 and the host is godaddy. Is it possible either of these could be the problem? Page is saved as login.htmlI've heard that php code doesn't execute correctly unless the page is pagename.php but this still had the same error.It seems that the it's exiting the script at the end of the first part of the first anchor tag.

Link to comment
Share on other sites

Here is my error now:Parse error: syntax error, unexpected T_ECHO in /home/content/55/8215455/html/login.php on line 17Below shows the lines the code is on too.

14 <?php15 if (isset($_SESSION['username']))16 then17	echo '<a href="saleslogout.php">Log Out</a>';18 else19 	echo '<a href="saleslogin.php">Log In</a>';20 ?>

I assume you meant save it as .php?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...