mds1256 Posted November 1, 2010 Share Posted November 1, 2010 Hello for my website i need to use variables from the select statement located in the code below, e.g. the account status (locked out etc). I hear global variabes are a NO NO. I have utilised session variables, is this the best way to achieve this? The code below sets a sessions variable if the user is locked out but on my home page i have just wrote an 'if' statement is see if this variable matches the criteria (if so then print out the DIV), is there a better way of doing this. function loginform($myusername, $mypassword, $ip) { $trimmedmyusername = trim($myusername); if($trimmedmyusername != "") { $sql="SELECT * FROM users, personal_details WHERE users.username='$trimmedmyusername' and users.password='$mypassword' AND users.username = personal_details.username"; $result=mysql_query($sql); $count=mysql_num_rows($result); $row = mysql_fetch_array($result, MYSQL_BOTH); if(lockout($trimmedmyusername)==1) { $_SESSION['accountstatus'] = "lockedout"; } elseif($count==1) { $_SESSION['myusername'] = $trimmedmyusername; $_SESSION['mypassword'] = $mypassword; $_SESSION['myname'] = $row['firstname']; $_SESSION['lastname'] = $row['lastname']; $_SESSION['title'] = $row['title']; $_SESSION['lastlogin'] = $row['lastlogin']; unset($_SESSION['accountstatus']); loginsucess($trimmedmyusername, $mypassword, $ip); } else { unset($_SESSION['myusername']); $_SESSION['myusername'] = $trimmedmyusername; loginfail($trimmedmyusername, $mypassword, $ip); $_SESSION['accountstatus'] = "incorrectdetails"; } } else { unset($_SESSION['accountstatus']); unset($_SESSION['myusername']); echo "Please enter a username"; } } <?php if(isset($_SESSION['accountstatus'])) { accountstatus($_SESSION['accountstatus']); } else { accountstatus(""); } ?> function accountstatus($status) { if($status == "lockedout") { echo "<div id='lockedoutimage' style='background:url(lockedout.jpg) no-repeat;'></div>"; } elseif($status == "incorrectdetails") { echo "<div id='lockedoutimage' style='background:url(incorrect.jpg) no-repeat;'></div>"; } else { echo ""; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.