cookie问题求解啊!!

cqheshuang 2010-07-31 01:46:38
麻烦问一下,COOKIE怎么没有反应啊?
a_index.php头部加入下面的代码检测:
require_once 'model/Checklogin.php';
CheckLogin::cksession($_COOKIE['user'],$_COOKIE['password']);


下面是CheckLogin.php的代码:
    function post()
{
if(isset($_POST['user']) && isset($_POST['password']))
{
$user = $_POST['user'];
$password = $_POST['password'];
$rs=mysql_fetch_array(mysql_query("select * from user")) or die(mysql_error());
if($rs[name] === $user && $rs[password] === md5($password))
{
setcookie("user",$user,time()*24*60*60);
setcookie("password",md5(trim($password)),time()*24*60*60);
info("Login Success!",'a_index.php');

}else{
info("Login Bad!",'index.php');
}
}
}

/**
* 判断是否获取COOKIE
*/
function ckcookie($user,$password)
{

$rs=mysql_fetch_array(mysql_query("select * from user")) or die(mysql_error());
if($user == $rs[name] && $password == $rs[password])
{
echo "<script>alert('Login Success!');location.href='a_index.php';</script>";
}
else
{
echo "<script>alert('Login Bad!');location.href='index.php';</script>";
exit;
}

}
...全文
168 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjb1216 2010-07-31
  • 打赏
  • 举报
回复
打酱油路过
xi4ojie 2010-07-31
  • 打赏
  • 举报
回复
setcookie用完了要刷新一下的。echo "<script language=\"javascript\">location.href='login.php';</script>";
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
info()方法里估计有header
xuzuning 2010-07-31
  • 打赏
  • 举报
回复
没有看到 CheckLogin::cksession 方法
也没有看到你在哪里设置了 cookie
Dleno 2010-07-31
  • 打赏
  • 举报
回复
你是不是把PHP文件保存成了带BOM头的UTF-8文件了????
是的话,要把BOM头取消了,不要保存带头的文件.


function post()
{
if(isset($_POST['user']) && isset($_POST['password']))
{
$user = $_POST['user'];
$password = $_POST['password'];
$rs=mysql_fetch_array(mysql_query("select * from `user` where `name` = '$user'")) or die(mysql_error());
if($rs['password'] == md5($password))
{
setcookie("user",$user,time()+24*60*60);//设置cookie时效,是当前时间加上时效时间,你的是用的*号,应该为+
setcookie("password",md5(trim($password)),time()+24*60*60);
info("Login Success!",'a_index.php');

}else{
info("Login Bad!",'index.php');
}
}
}

/**
* 判断是否获取COOKIE
*/
function ckcookie($user,$password)
{

$rs=mysql_fetch_array(mysql_query("select * from `user` where `name` = '$user'")) or die(mysql_error());
if($rs['password'] == md5($password))
{
echo "<script>alert('Login Success!');location.href='a_index.php';</script>";
}
else
{
echo "<script>alert('Login Bad!');location.href='index.php';</script>";
exit;
}

}
CunningBoy 2010-07-31
  • 打赏
  • 举报
回复
你的代码没有贴全吧?
我都没看header语句在哪里。
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
我都看了啊。。。没有啊。。就KYZY你给我的那个加上去exit就不行。。。我checklogin.php前面都没有用HEADER和什么啊?
就一个类,下面就是function...这个页面也没有调用其它页面了
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
我都看了啊。。。没有啊。。就KYZY你给我的那个加上去exit就不行。。。我checklogin.php前面都没有用HEADER和什么啊?
就一个类,下面就是function...这个页面也没有调用其它页面了
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
我都看了啊。。。没有啊。。就KYZY你给我的那个加上去exit就不行。。。我checklogin.php前面都没有用HEADER和什么啊?
就一个类,下面就是function...这个页面也没有调用其它页面了
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
也不能有错误警告notice之类的,除非你将它们屏蔽了,不然也算输出
CunningBoy 2010-07-31
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 cqheshuang 的回复:]
出现这两个错误:
<form name="login" action="
Warning: Cannot modify header information - headers already sent by (output started at C:\wwwroot\cf\admin\index.php:11) in C:\wwwroot\cf\appl\model\checklogin.p……
[/Quote]
header语句之前,不能出现echo,print等输出语句
也不能出现HTML页面的输出。
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
这是info方法里header的错误,请在页面最前面进行ob_start();或者将相应的错误修改(总之在header之前不能有任何输出)
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
出现这两个错误:
<form name="login" action="
Warning: Cannot modify header information - headers already sent by (output started at C:\wwwroot\cf\admin\index.php:11) in C:\wwwroot\cf\appl\model\checklogin.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at C:\wwwroot\cf\admin\index.php:11) in C:\wwwroot\cf\appl\model\checklogin.php on line 18
-
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
首先在你登陆的时候:
function post()
{
if(isset($_POST['user']) && isset($_POST['password']))
{
$user = $_POST['user'];
$password = $_POST['password'];
$rs=mysql_fetch_array(mysql_query("select * from user")) or die(mysql_error());
if($rs[name] === $user && $rs[password] === md5($password))
{
setcookie("user",$user,time()*24*60*60);
setcookie("password",md5(trim($password)),time()*24*60*60);
echo $_COOKIE['user'].'-'.$_COOKIE['password'];exit;//这块输出下看看是否成功了
info("Login Success!",'a_index.php');

}else{
info("Login Bad!",'index.php');
}
}
}
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
还是空白。。没有反应
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 cqheshuang 的回复:]
没有。。。我测试过了。。但是要刷两次才能出现正常COOKIE值
[/Quote]

cookie本来就应该是第二次开始才生效的
kyzy_yy_pm 2010-07-31
  • 打赏
  • 举报
回复
if(($user == $rs[name]) && ($password == $rs[password]))应该这样的
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
没有。。。我测试过了。。但是要刷两次才能出现正常COOKIE值
gumwzg 2010-07-31
  • 打赏
  • 举报
回复
浏览器是否把cookie 禁用了呢?
cqheshuang 2010-07-31
  • 打赏
  • 举报
回复
没有,点进去直接就是空白了
加载更多回复(4)

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧