<?php
session_cache_expire(30);
session_start();
header("Content-Type: text/html; charset=UTF-8");
session_regenerate_id(true);
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
require_once("_conn.php");
foreach ($_POST as $key => $value) {
$$key = mysql_real_escape_string(stripslashes(htmlspecialchars(strip_tags($value))));
}
foreach ($_GET as $key => $value) {
$$key = mysql_real_escape_string(stripslashes(htmlspecialchars(strip_tags($value))));
}
if( empty($_POST['token']) || $_POST['token'] != $_SESSION['token'] )
header("Location: default.php?act=error");
$valid_username = preg_match("/^[A-Za-z]\w{6,20}[A-Za-z_0-9]$/D",$username);
$valid_password = preg_match("/^[A-Za-z]\w{6,20}[A-Za-z_0-9]$/D",$password);
if (!$valid_username || !$valid_password)
{
header("Location: default.php?act=error");
}
$password = SALT . $password;
$password = sha1($password);
$q = "SELECT * FROM administrators "
."WHERE username='" . $username . "' "
."AND password='". $password . "' "
."LIMIT 1";
$r = mysql_query($q);
if ( $obj = @mysql_fetch_object($r) )
{
// Login good, create session variables
$_SESSION["nt_id_conn"] = $obj->idadministrator;
$_SESSION["nt_id_username"] = $username;
$_SESSION["nt_id_time"] = time();
$_SESSION["nt_ip"] = $_SERVER["REMOTE_ADDR"];
// Redirect to member page
header("Location: main.php");
}
else
{
// Login not successful
header("Location: default.php?act=error");
}
//unset($_SESSION['token']);
session_write_close();
?>
|