Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/121336-show-link-if-logged-in/
Share on other sites

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?

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.

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.

}
?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.