By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

how do i check if user is logged on?

P: 3
i would like to echo different links on each page depending on if the user is logged on or not,
e.g "log on" or "register" if they are not and "change style" if they are,
how do i do this?
cheers
Jul 10 '06 #1
Share this Question
Share on Google+
2 Replies


sashi
Expert 100+
P: 1,754
Hi there,

emm.. am sure every user allowed to login must have an access level assigned.. rite?? well.. then you can forward each user to a specific page based on their access level.. good luck my fren.. :)
Jul 10 '06 #2

ronverdonk
Expert 2.5K+
P: 4,258
Assuming that you already know how to get the user to login, the following handles your problem.
[PHP]<?php
session_start();
/*--------------------------------------------------------------*
* Check if user is logged in. This check assumes that you have *
* saved the user's session data (in this case the 'username' *
* in the $_SESSION after a valid login. *
*--------------------------------------------------------------*/
if (!array_key_exists('username', $_SESSION)) {
// User is not logged-in, so display your 'please login' links
// ......................................
}
else {
// user is validly logged in, display whatever you want to
// ................................................
}
?>[/PHP]

Ronald :cool:
Jul 22 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.