Hey, I’m new to Php and I need your help. On my website ([URL=”http://www.italk.francoiscox.org”]Fire Tiger[/URL]) I have a Login system, but I want to have pages wich are avaible to visitors and members (ex:Index) , but when the user is loged in and goes to that page, themenu shows “register , Login”, but hat member is allready loged in. So I want to know hot make a menu that changes according to if it is a visitor or a member,
@Mr__E__CrypticApr 10.2009 — #When the user is signing in, have the sign-in code populate $_SESSION with a value that indicates if a user is logged in or not, eg:
$_SESSION['isLoggedIn'] = 1;
Then just run a simple conditional check where you currently display your form or menu entry:
[code=php]<?php if( (!isset($_SESSION['isLoggedIn'])) or ($_SESSION['isLoggedIn'] !== 1) ) { //Code if member is NOT logged in } else { //Code if member is logged in } ?>[/code]
@abzApr 17.2009 — #I would say when the user logs in, save their userID on the session rather than a boolean value. [code=php]session_start(); $_SESSION['user'] = $userid; [/code]
Then depending how many admin you are having, just check the user's ID against that of the admin to decide what to write: [code=php] <?php if( $_SESSION['user'] == $adminid ) { //Code for administrators } else if ($_SESSION['user'] ) { //Code if member is logged in } else { // default to not logged in } ?> [/code]