Dada78 Posted August 26, 2008 Share Posted August 26, 2008 Hello, I have a website where one section requires a login to get to the user control panel. I would like to add a link on other pages outside of the control panel so that if the user navigates away from the control panel they can click a link to return back to the control panel if they are logged in. How could I go about doing something like this? -Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Just check for the logged in session variable (assuming that you use sessions), and if it exists, just echo a link. Quote Link to comment Share on other sites More sharing options...
Dada78 Posted August 26, 2008 Author Share Posted August 26, 2008 I am using sessions but if I include that to the top of the pages outside of the control panel. Wouldn't that make it where they had to be logged in to view it? If that is the case that is not what I want. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 26, 2008 Share Posted August 26, 2008 <?php session_start(); if($_SESSION['logged_in']){ echo"The new link for the current user who logged in"; } ?> Quote Link to comment Share on other sites More sharing options...
Dada78 Posted August 26, 2008 Author Share Posted August 26, 2008 That doesn't work, nothing shows. Also that means the link as to be at the very top of the page and I don't want it there. Any other ideas? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Uhh...it can be wherever you want, what in the world are you talking about? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 It would work fine if you understand how to use session variables That doesn't work, nothing shows. Also that means the link as to be at the very top of the page and I don't want it there. Any other ideas? Quote Link to comment Share on other sites More sharing options...
Dada78 Posted August 26, 2008 Author Share Posted August 26, 2008 No it can not be where ever I want it. Session Start has to be and the top of the page before and HTML is outputted. You are right, I don't know how sessions work which is why I am here asking for help. I don't deal with php, I strictly deal with XHTML and CSS. This is was a project started by me and a friend as he knew php. So he was going to do the php and I was going to do the layout and design, which I have done. Only thing is he couldn't finish it because he was killed in a car wreck. So it has left me to try to figure it out and finish. So can anyone help? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 session_start() does not dictate where the Output of your variable will be, this does if($_SESSION['logged_in']){ echo"The new link for the current user who logged in"; } So put the IF statement where you want it to display. Change the name to match the name you use for your session variable that get's set when they log in. Quote Link to comment Share on other sites More sharing options...
Dada78 Posted August 26, 2008 Author Share Posted August 26, 2008 I understand that part but this... session_start(); Has to be at the very top of the page before any HTML is outtputed correct? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Yes Quote Link to comment Share on other sites More sharing options...
waynew Posted August 26, 2008 Share Posted August 26, 2008 Say you have a SESSION variable called $_SESSION['username'] (username) etc. On pages outside of the Control Panel, just place the following PHP (modified according to the session variables you have of course): <?php if(isset($_SESSION['username'])){ //Change this according to variable name echo '<a href="controlpanel.php">Control Panel</a>'; //Change url of course. } ?> Quote Link to comment Share on other sites More sharing options...
Dada78 Posted August 26, 2008 Author Share Posted August 26, 2008 Just curious, I have noticed the two codes that were posted were about the same except one has if(isset and one doesn't have the isset. What is the difference? 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.