/    Sign up×
Community /Pin to ProfileBookmark

How can I reference whether or not someone is logged in?

I want to do something like:

[QUOTE]

if (loggedIn == true) {

}

[/QUOTE]

How do I reference that? I know there’s many different ways to do it, depending on what you’re using. But what are some common ways?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindMay 07.2010 — Most common is probably via $_SESSION

In this app, I track a number of actions based on the users email, so I just check for that where necessary.

[code=php]
// among other sanitization/verification
$email = mysql_real_escape_string($_POST['email']);

$query = "select * from pten_toolbox_users where email = '$email' limit 1";
$result = mysql_query($query, $link);

if ($users = mysql_fetch_assoc($result)){

// set what you want to track 'logged in status' to a session variable
// be sure to session_start() at the top of every page that needs validation
// even if you don't use the session, you still need to pass the variables via session_start()
$_SESSION['user_email'] = $email;
// email registered; redirect to vote
header("Location: index.php");

[/code]
Copy linkTweet thisAlerts:
@tirnaMay 08.2010 — In the authentication script where you check if the user entered username/password pair match that in your database, you assign a value to a session variable if the username/password are correct.

Then on every page where you need a user to be logged in you simply check if the above session variable exists [B]and[/B] if it is set to the correct value. If it is, then you let the script in the web page run.
Copy linkTweet thisAlerts:
@narutodude000authorMay 08.2010 — I found a function in my file that determines whether or not an user is logged in (I'm using a site builder). Thanks anyways.
×

Success!

Help @narutodude000 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.29,
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,
)...