m.huber614 Posted August 15, 2011 Share Posted August 15, 2011 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 More sharing options...
Ingolme Posted August 15, 2011 Share Posted August 15, 2011 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 More sharing options...
m.huber614 Posted August 15, 2011 Author Share Posted August 15, 2011 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 More sharing options...
Ingolme Posted August 15, 2011 Share Posted August 15, 2011 OK, I'll tell you that your need to run this code on a PHP server. The PHP code isn't being parsed. Use a PHP extension on the file. Link to comment Share on other sites More sharing options...
m.huber614 Posted August 15, 2011 Author Share Posted August 15, 2011 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 More sharing options...
Ingolme Posted August 15, 2011 Share Posted August 15, 2011 OK, the PHP is now being parsed. Now here's where the information of my previous post comes in. Your syntax is not PHP, that's BASIC. Link to comment Share on other sites More sharing options...
m.huber614 Posted August 15, 2011 Author Share Posted August 15, 2011 I'm not sure if this is what you meant but I took another look at PHP samples and apparently the "then" was what was screwing anything up. Took that out and now it works great. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.