Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/131269-check-login/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/131269-check-login/#findComment-681901
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/131269-check-login/#findComment-682006
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.