aznkidzx Posted January 28, 2009 Share Posted January 28, 2009 Okay my navigation menu, I have all these regular things. I also have Login Register and Logout. This is the code for my navigation menu. <ul id="navigation" name="navigation"> <li><a href="index.html">home</a></li> <li><a href="about.html">about</a></li> <li><a href="portfolio.html">portfolio</a></li> <li><a href="contact.php">contact</a></li> <li><a href="register.php">register</a></li> <li><a href="login.php">login</a></li> <li><a href="logout.php">logout</a></li> I want to make it so that only when people are logged in, the logout navigation is there. How do I do so? Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 How are you tracking wether or not your users are logged in? Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I don't. I am trying to find out how to do that as well. Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 So you need to sort out your login system too? Why not do that first? Once your tracking users via sessions its easy enough to display different things to different users based on whether or not there logged in. eg; session_start(); if ($_SESSION['is_logged_in'])) { // display data for logged in users } else { // display data for users who aren't logged in. } Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 What do I do with that code? Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Nothing without a login system. You need to build your login system first. Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I have a login system and it works fine Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Then, when you log your users in set a session variable (eg; $_SESSION['is_logged_in']) to true. You can then use this to track whether or not your users are logged in, from there its just a simple if statement like I just showed you. Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I know but where do I insert that code? Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Wherever you want to make a decision about whether or not something should be outputed based on whether or not your user is logged in or not. eg; session_start(); if ($_SESSION['is_logged_in'])) { // display data for logged in users } else { // display data for users who aren't logged in. } Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 Do I have to insert the <?php and ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Yes. Its just a simple example. Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 So in my navigation menu, I put this? Wait also sorry for being stupid and useless. <ul id="navigation" name="navigation"> <li><a href="index.html">home</a></li> <li><a href="about.html">about</a></li> <li><a href="portfolio.html">portfolio</a></li> <li><a href="contact.php">contact</a></li> <li><a href="register.php">register</a></li> <li><a href="login.php">login</a></li> <?php session_start(); if ($_SESSION['is_logged_in'])) { // display data for logged in users } else { // display data for users who aren't logged in. } ?> <li><a href="logout.php">logout</a></li> </ul> -------------- I just tried that code and this is the error Parse error: syntax error, unexpected ')' in /home/a7856302/public_html/portfolio/index.html on line 29 Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Based on your example above. <?php session_start(); ?> <ul id="navigation" name="navigation"> <li><a href="index.html">home</a></li> <li><a href="about.html">about</a></li> <li><a href="portfolio.html">portfolio</a></li> <li><a href="contact.php">contact</a></li> <li><a href="register.php">register</a></li> <li><a href="login.php">login</a></li> <?php if (isset($_SESSION['is_logged_in'])) { echo " <li><a href=\"logout.php\">logout</a></li>"; } ?> Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I used the code you presented and after I logged in, the logout isn't there anymore. Even when I am not logged in it isn't there. Would you need my login code? Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Did you set $_SESSION['is_logged_in'] to true when your users login? Do you understand how your login system even works? Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 To tell the truth, no I don't know how it works. Also in my login system code, I only find this. <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 To tell the truth, no I don't know how it works. Then your going to have a pretty hard time using it. Did you write the system from a tutorial or just download it from somewhere? Are you actually interested in learning php or just want this stuff working? Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 Both. I downloaded. Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Both. I downloaded. That doesn't really answer the main gist of the question. What Im getting at is basically this. If you are interested in learning php then simply downloading code is likely to make things harder. You need to build your login system from scratch so as you understand how it works so you can make the desired changes you may need. If your not acxtually interested in learning php and just want this stuff working, Id suggest you find a programmer. Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I want to learn too. Also, how do I open php.exe? I installed Wampserver and it came with it. I open php.exe and only the command prompt pops up, nothing else. Inside command prompt is nothing. How do I run it? Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 I want to learn too. Then Id suggest finding a decent 'php login' tutorial and building your own login system. Even though the objective of your post was quite simple, it seems to me your trying to run before you can even walk. Also, how do I open php.exe? You don't open it. It is used to execute command line php scripts. eg; php.exe mysript.php Quote Link to comment Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 I found a login system tutorial off YouTube. Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 I found a login system tutorial off YouTube. Good for you. Now all you need to is learn from it and understand why it works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.