<?php
/**
* Sanitize user input to prevent SQL injection. Use this on ALL user input!
* This function is from CodeIgniter.
* @param string $data
* @return string
*/
function mssql_escape_string($data) {
if(!isset($data) or empty($data)) return '';
if(is_numeric($data)) return $data;
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', // 11
'/\x0c/', // 12
'/[\x0e-\x1f]/' // 14-31
);
foreach($non_displayables as $regex)
$data = preg_replace($regex,'',$data);
$data = str_replace("'","''",$data);
return $data;
}
//Store $_POST variables
$username = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : '';
$password = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : '';
if(isset($_POST) && !empty($_POST))
{
//Connect to SQL
mssql_connect('localhost', 'youraccount', 'yourpassword');
$res = mssql_query("SELECT * FROM users WHERE username='{$username}' and password='{$password}'") or die("Query Failed");
$num = ; // This sees how many values we got back
if(mssql_num_rows($res))
{
//Store information + Log time
}
else
{
echo "Login Fail or whatever";
}
}
?>