PHP Tutorial : Membership script – Users Login
Jun 13, 2009 Complete Scripts
Welcome back to the simple php membership script tutorial.
Last time we saw how to create the php user registration function. We will continue today with the php login function and will also see how to check if a user is logged in or not.
<?php function loginUser($user, $pass) { if(empty($user) || empty($pass)) { exit(); }else{ $user = addentities($user); $pass = addentities($pass); $sql = "select * from users where user = '$user' and pass = '$pass'"; $rs = mysql_query($sql); if($rs) { if(mysql_num_rows($rs) != 0) { $row=@mysql_fetch_object($rs); $_SESSION['logged'] = "yes"; $_SESSION['user'] = $user; refreshPage(0, $_SERVER['PHP_SELF']); }else{ print "Wrong username and password"; } } } } ?>
Now, how simple is it to check if a user is logged in?
<?php if(checkLogged() == false) { print "You are not authorized to see this page, please login first!"; }elseif(checkLogged() == true) { print "Welcome $_SESSION[user]"; } ?>
Please note that you must add the session_start(); function at the very begining of the script, before outputing anything else! Check this blog for detailed instructions on how to use sessions.
See you next time and happy coding!
Tags: check logged in user, login area, membership script, php login user, php membership, users login


June 13th, 2009 at 10:08 am
[...] here to read the rest: 13 Jun PHP Tutorial : Membership script – Users Login Posted by: admin / Category: Complete Scri… Posted in PHP | Tags: coding, membership, membership-script, PHP, php-register, shown-you, [...]
June 13th, 2009 at 5:24 pm
[...] function and also I will show you how to check if a user is logged in or not. Original post: PHP Tutorials – Crivion's Blog » Blog Archive » PHP Tutorial … This entry is filed under Membership. You can follow any responses to this entry through the RSS [...]