Jump to content

"make button visible if user logged in..."


xcali

Recommended Posts

Hi gang

 

Once again i mest up and posted in wrong forum :/. anyway noob question:

I browsed through Google, but none of the web pages i visited gave me the answer i am searching for.

I have my website. When guests first enter the web page i have a navigation on the top ( theres 3 buttons: home / sign in / logout)

What i would like, is to have a check - if the user is already logged in, then display the logout button, otherwise have the button hidden.

May i get some pointers on this? Maybe someone knows where i can find a web page that could explain this to me.

I'm not sure if it is suppose to be set as a global variable which would be passed from page to page, or a simple php check that would look for a cookie, before loading of the actual html site.

 

Please advise

 

Thank you

Link to comment
Share on other sites

Example:

 

<?php
// Check if user is logged in
if(isset($_SESSION['uid'])){ // where uid is a session variable being saved upon logging in
   echo "Logout"; // echo the logout button
}else{
   echo "Login"; // echo the login button
}
?>

 

Very basic example but it should do the trick ;)

Link to comment
Share on other sites

thank you for the answers guys

 

i did find a lot of information about sessions and such and i have a lot to cover

what i don't understand though is... are cookies needed if we have everything stored in a session?

i mean would u suggest creating both session and a cookie and then pulling info from the cookies (like userid) or saving it in both cookie and the session, or maybe creating only a session ?

 

Link to comment
Share on other sites

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.