![]() |
#2
CplusHua2013-04-26 12:52
|
这是我的login.php页面

ini_set(”output_buffering”, “1″);
session_start();
//echo $_SESSION['code'];
//定义一个常量,用来授权调用
define('IN_TG', true);
//定义一个CSS调用常量
define('SCRIPT', 'login');
require dirname(__FILE__).'/includes/common.inc.php';//获取当前路径
//开始处理登录状态
if ($_GET['action'] == 'login'){
//防止恶意注册,跨站攻击
_check_code($_POST['code'] , $_SESSION['code']);
//引入验证文件
include ROOT_PATH.'includes/login.func.php';
//开始接受数据
$_clean = array();
$_clean['username'] = _check_user($_POST['username'],2,20);
$_clean['password'] = _check_password($_POST['password'], 6);
$_clean['time'] = _check_time($_POST['time']);
//print_r($_clean);
//到数据库验证
if (!!$_rows = _fetch_array("SELECT gt_username,gt_uniqid FROM gt_user WHERE gt_username='{$_clean['username']}' AND gt_password='{$_clean['password']}' AND gt_active='' LIMIT 1")){
/*echo '登录成功!';
echo $_rows['gt_username'];
echo $_rows['gt_uniqid'];*/
_close_db();//关闭数据
_session_destroy();//销毁 session
_setcookies($_rows['gt_username'], $_rows['gt_uniqid']);//调用 cookie函数
//setcookie('username',$_rows['gt_username']);
//setcookie('uniqid',$_rows['gt_uniqid']);
//跳转方法一
//_location('登录成功!', 'index.php');
//跳转方法二,还是有点问题
_location(null, 'index.php');
} else {
_close_db();
_session_destroy();
_location('用户名密码不匹配,或者该账户未被激活!','login.php');
}
}
这是我写cookie函数的页面

//这个登录成功后跳转到首页上的函数
function _location($_info,$_url){
if (!empty($_info)){
echo "<script type='text/javascript'>alert('$_info');location.href='$_url';</script>";
exit();
//echo "<script type='text/javascript'>alert('".$_info."');history.back();</script>";
//exit;
} else {
header('Location:'.$_url);
}
}
//这个是设置COOKIE的函数
/**
* 生成 cookies
* Enter description here ...
*/
function _setcookies($_username,$_uniqid){
setcookie('username',$_username);
setcookie('uniqid',$_uniqid);
}