<?php
session_start();
header('conten-type:text/html;charset=utf-8');
if($_GET['action'] == "logout"){
unset($_SESSION['admin_name']);
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
echo "<script type='text/javascript'>alert('注销成功!');</script>";
echo "<script type='text/javascript'>window.location.href='index.php'</script>";
exit;
}
if (isset($_POST['login'])) {
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysql_error());
}
mysql_query("set names utf8");
mysql_select_db( 'table-db',$conn);
$admin_name = $_POST['name'];
$admin_pwd = $_POST['pwd'];
if(preg_match('/^[a-zA-Z][a-zA-Z0-9]{4,12}$/',$admin_name)){
$check_query = mysql_query("select * from web_admin where admin_name='$admin_name' and admin_pwd='$admin_pwd'
limit 1");
if($result = mysql_fetch_array($check_query)){
$_SESSION['admin_name'] = $admin_name;
echo "<script type='text/javascript'>alert('登陆成功!');</script>";
echo "<script type='text/javascript'>window.location.href='main.php'</script>";
} else {
echo "<script type='text/javascript'>alert('登陆失败,请重试!');</script>";
}
}else{
echo "<script type='text/javascript'>alert('请输入合法用户名!');</script>";
}
}
?>