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
https://forums.phpfreaks.com/topic/94097-make-button-visible-if-user-logged-in/
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 ;)

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 ?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.