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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/ 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748947 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748951 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. } Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748953 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748963 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748969 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 Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748980 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748982 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748986 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. } Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748988 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 ?> Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748989 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Yes. Its just a simple example. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748990 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 Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748991 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748993 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748996 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748998 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'])) { ?> Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749000 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749017 Share on other sites More sharing options...
aznkidzx Posted January 28, 2009 Author Share Posted January 28, 2009 Both. I downloaded. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749021 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749023 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? Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749026 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 Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749033 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749040 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. Link to comment https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.