runnerjp Posted November 3, 2008 Share Posted November 3, 2008 quick question... im trying to neaten up my code and currently looking into my check login to make it work better! ok so my page looks like this (short clip) <?php session_start(); require_once '../settings.php'; checkLogin ('1 2'); include "connect.php"; //mysql db connection here include "../getuser.php"; seems im checking my login via a session function checkLogin($levels) { global $db; $kt = split(' ', $levels); if (!$_SESSION['logged_in']) { $access = false; if (isset($_COOKIE['cookie_id'])) { //if we have a cookie $query = 'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr($_COOKIE['cookie_id']); if ($db->RecordCount($query) == 1) { //only one user can match that query $row = $db->getRow($query); //let's see if we pass the validation, no monkey business if ($_COOKIE['authenticate'] == md5(getIP() . $row->Password . $_SERVER['USER_AGENT'])) { //we set the sessions so we don't repeat this step over and over again $_SESSION['user_id'] = $row->ID; $_SESSION['logged_in'] = true; //now we check the level access, we might not have the permission if (in_array(get_level_access($_SESSION['user_id']), $kt)) { //we do?! horray! $access = true; } } } } } else { $access = false; if (in_array(get_level_access($_SESSION['user_id']), $kt)) { $access = true; } } if ($access == false) { header('Location: http://www.runningprofiles.com/error.php'); } } how could i make it so that these are done include "connect.php"; //mysql db connection here include "../getuser.php"; only if checkLogin ('1 2'); is correct Quote Link to comment https://forums.phpfreaks.com/topic/131269-check-login/ Share on other sites More sharing options...
runnerjp Posted November 4, 2008 Author Share Posted November 4, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/131269-check-login/#findComment-681892 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 you will need your function to return true if the user is logged in no probs or false if there's a problem. Then have: if ( checkLogin('1 2')) { include "connect.php"; //mysql db connection here include "../getuser.php"; } Which tests for the checkLogin function returning true.. adam Quote Link to comment https://forums.phpfreaks.com/topic/131269-check-login/#findComment-681901 Share on other sites More sharing options...
runnerjp Posted November 4, 2008 Author Share Posted November 4, 2008 well i did this session_start(); require_once '../settings.php'; checkLogin ('1 2'); include "connect.php"; //mysql db connection here include "../getuser.php"; include "checkinfo.php"; but it still carrys out include "checkinfo.php"; Quote Link to comment https://forums.phpfreaks.com/topic/131269-check-login/#findComment-681983 Share on other sites More sharing options...
trq Posted November 4, 2008 Share Posted November 4, 2008 well i did this session_start(); require_once '../settings.php'; checkLogin ('1 2'); include "connect.php"; //mysql db connection here include "../getuser.php"; include "checkinfo.php"; but it still carrys out include "checkinfo.php"; Because, as the previous poster pointed out, you need to use an if conditional. Read the previous reply again if in fact you read it at all the first time. Quote Link to comment https://forums.phpfreaks.com/topic/131269-check-login/#findComment-682006 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.