PHP LOGIN

mysql 配置

realmd数据库

zxl表

表中记录 ID=1 , Username='uu' ,Password='pp'

login.php

<?php

if (isset($_REQUEST['attempt']))
{
$link = mysql_connect('localhost','root','2009') or die('cant connect to database');
mysql_select_db('realmd');

$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['password']);

$query = mysql_query("
SELECT Username
FROM zxl
WHERE Username = '$user'
AND Password = '$password'
") or die(mysql_error());

$total = mysql_num_rows($query);

if($total > 0)
{
//login
session_start();
$_SESSION['user'] ='zxl';
header('location: dashboard.php');

}
else
{
//do nothing
echo 'nothing';
}
}
?>

<form action="login.php?attempt" method="POST">
User <input type="text" name="user" /><br />
Pass <input type="password" name="password" /><br />
<input type="submit" />
</form>


dashboard.php

<?php
session_start();
if(!isset($_SESSION['user'])){
header('location: login.php');
}
?>

hello


 

你可能感兴趣的:(PHP LOGIN)