/    Sign up×
Community /Pin to ProfileBookmark

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,

Thanks ‘

Fire Cat

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@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]
Copy linkTweet thisAlerts:
@Fire_CatauthorApr 16.2009 — Ok thanks, but what if I wnat to have a Admin menu?

Ex:

Visitor:Home - Register - Login

Member:Home - Forum - Chat - Logout

Admin:Home - Forum - ACP* - Chat - Logout



*Admin control Panel
Copy linkTweet thisAlerts:
@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]
×

Success!

Help @Fire_Cat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...