Skip to content

Instantly share code, notes, and snippets.

@ZachMoreno
Created February 21, 2012 07:40
Show Gist options
  • Save ZachMoreno/1874894 to your computer and use it in GitHub Desktop.
Save ZachMoreno/1874894 to your computer and use it in GitHub Desktop.
Session Start
<?php
function authenticate_user($login, $password, $key)
{
$val = set_codes();
$query = "select * from users where login='$login' and password = encode('$password', '$key')";
$result = mysql_query ($query);
$row = mysql_fetch_row($result);
if (mysql_num_rows($result) > 0)
{
$_SESSION['auth'] = $val;
$_SESSION['id'] = $row[0];
}
else
{
$_SESSION['auth'] = "Incorrect Login";
}
}
?>
<?php
$val = set_codes();
if (!isset ($_SESSION['auth']) || $_SESSION['auth'] != $val)
{
if (isset($_POST['username']))
{
authenticate_user (mysql_prep($_POST['username']), mysql_prep($_POST['password']), KEY);
}
}
?>
<?php
session_start();
if(isset($_GET['killsession']))
{
session_destroy();
session_start();
}
?>
<?php
function set_codes()
{
if (!isset($_SESSION['validcode']))
{
$_SESSION['validcode'] = rand (1000000, 9000000);
$val = $_SESSION['validcode'];
return $val;
}
else
{
$val = $_SESSION['validcode'];
return $val;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment