38 lines
1000 B
PHP
38 lines
1000 B
PHP
<?php
|
|
//to check if someone is logged in, require this file and then after the require, globalize $is_logged_in, like so:
|
|
/*
|
|
require_once('is_logged_in.php');
|
|
global $is_logged_in;
|
|
|
|
if($is_logged_in)
|
|
{
|
|
...
|
|
}
|
|
*/
|
|
require_once('database.php');
|
|
global $connect;
|
|
$is_logged_in = false;
|
|
session_start();
|
|
if(isset($_SESSION['login_data']))
|
|
{
|
|
// typical login data consists of: base64_encode('username|5f4dcc3b5aa765d61d8327deb882cf99')
|
|
$login_data = base64_decode($_SESSION['login_data']);
|
|
if(strpos($login_data,'|') && substr_count($login_data,'|') == 1) // we want at least one | but just one
|
|
{
|
|
list($username,$password) = explode('|',$login_data);
|
|
if(strlen($password) == 32) // md5
|
|
{
|
|
$sql = 'SELECT username FROM accounts WHERE username = "'.htmlentities($username).'" AND password = "'.$password.'"';
|
|
$query = mysql_query($sql);
|
|
if(mysql_num_rows($query) > 0)
|
|
{
|
|
$is_logged_in = true; // success
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if($is_logged_in === false)
|
|
{
|
|
unset($_SESSION['login_data']);
|
|
}
|
|
?>
|