conker87 Posted June 14, 2007 Share Posted June 14, 2007 At the moment, when my members login their details get put into session variables, that's fine - works great. However, what annoys me is that whenever I want to validation someone being logged in, I have to use the following in each and every place this happens: <?php if (isset($_SESSION['username'], $_SESSION['password'])) { $check = mysql_num_rows(mysql_query("SELECT * FROM `members_table` WHERE `username_field` = '".$_SESSION['username']."' AND `password_field` ='".$_SESSION['password']."'")); if ($check == 0) { echo "<title>love v4 // login: error</title><h2>Invalid Username/Password.</h2>"; } else if ($check == 1) { } } ?> I'm wondering if I could make this into some sort of function to go into my global functions page. Such as the following: <?php function loveLogged() { if (isset($_SESSION['username'], $_SESSION['password'])) { $check = mysql_num_rows(mysql_query("SELECT * FROM `members_table` WHERE `username_field` = '".$_SESSION['username']."' AND `password_field` ='".$_SESSION['password']."'")); if ($check == 0) { return false; } else if ($check == 1) { return true; } } } ?> With the code in the page being: <?php if (loveLogged()) { //Do true stuff. } ?> Would this work, and if not, how would I change it for it to work? Quote Link to comment https://forums.phpfreaks.com/topic/55628-loggedin-function/ Share on other sites More sharing options...
Trium918 Posted June 14, 2007 Share Posted June 14, 2007 Try and see if it will work! If not, come back. Quote Link to comment https://forums.phpfreaks.com/topic/55628-loggedin-function/#findComment-274880 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.