登录验证时,无法获得$_SESSION的值
print_r($_COOKIE);时候,输出
Array ( [PHPSESSID] => 7rpor1tugvmu2dpcrfsqil8lv1 )login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0037)http://localhost:8008/admin/Login.asp -->
<HTML><HEAD><TITLE>企业管理系统后台登陆</TITLE>
<SCRIPT language=javascript>
<!--
function SetFocus()
{
if (document.Login.UserName.value=="")
document.Login.UserName.focus();
else
document.Login.UserName.select();
}
/*function CheckForm()
{
if(document.Login.UserName.value=="")
{
alert("请输入用户名!");
document.Login.UserName.focus();
return false;
}
if(document.Login.Password.value == "")
{
alert("请输入密码!");
document.Login.Password.focus();
return false;
}
if (document.Login.CheckCode.value==""){
alert ("请输入您的验证码!");
document.Login.CheckCode.focus();
return(false);
}
}*/
//-->
</SCRIPT><META content="text/html; charset=gb2312" http-equiv=Content-Type><!-- 调用CSS,JS --><STYLE type=text/css>BODY {
BACKGROUND-IMAGE: url(login1_08.gif); LINE-HEIGHT: 1.5; BACKGROUND-COLOR: #bbd9f5; MARGIN-TOP: 0px; BACKGROUND-REPEAT: repeat-x; FONT-FAMILY: "宋体"; MARGIN-BOTTOM: 0px; COLOR: #546d87; MARGIN-LEFT: 0px; FONT-SIZE: 12px; FONT-WEIGHT: normal
}
</STYLE><META name=GENERATOR content="MSHTML 8.00.6001.19190"></HEAD>
<BODY>
<TABLE border=0 cellSpacing=0 cellPadding=0 width=990 align=left height=650>
<TBODY>
<TR>
<TD vAlign=top width=318>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299 align=right><IMG
src="{$sty->template_dir}/images/login1_01.gif" width=318
height=299></TD></TR>
<TR>
<TD height=351 align=right><IMG
src="{$sty->template_dir}/images/login1_04.gif" width=318
height=351></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=366>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299
background="{$sty->template_dir}/images/login_6.gif" > </TD></TR>
<TR>
<TD height=96 vAlign=top background="{$sty->template_dir}/images/login_9.gif" no-repeat>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=25 width="25%"> </TD>
<TD vAlign=top width="48%">
<FORM onSubmit="return CheckForm();" method=post name=Login action="index.php?c=login&m=login" target=_parent><LABEL><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="username" type="text" id="username" class=txt> </LABEL></TD>
<!-- id=UserName class=txt tabIndex=1 name=UserName> </LABEL></TD>-->
<TD rowSpan=3 width="27%"><INPUT border=0
src="{$sty->template_dir}/images/login_2.gif" width=57 height=55
type=image></TD></TR>
<TR>
<TD height=25> </TD>
<TD><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="password" type="text" id="password" class="txt"/>
<!-- id=password class=txt tabIndex=2 type=password name=Password> -->
</TD></TR>
<TR>
<TD height=25> </TD>
<TD><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="yzm" type="text" id="yzm" class="yzm" />
<!-- id="checkcode" tabIndex=300 size=12 name="checkcode" /> -->
<IMG style="margin-top:6px;"
src="../Core/yzm.class.php" width="156" height="60" onclick="this.src='../Core/yzm.class.php?id='+Math.random();" style="cursor:pointer" alt="看不清,请点击更换" title="看不清,请点击更换"/> </TD></TR></FORM></TBODY></TABLE></TD></TR>
<TR>
<TD height=255 background="{$sty->template_dir}/images/login1_07.gif">
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD
height=129> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=318>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299 background="{$sty->template_dir}/images/login1_03.gif"
align=left> </TD></TR>
<TR>
<TD height=351 background="{$sty->template_dir}/images/login1_06.gif "
align=left> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<SCRIPT language=JavaScript type=text/JavaScript>
CheckBrowser();
SetFocus();
</SCRIPT></BODY>
</HTML>
<?php
class loginAction extends Action{ function login(){
print_r($_COOKIE);
print_r($_POST);
exit;
if(md5(strtoupper($_POST['yzm']))==$_COOKIE['yzm']){//如果验证码正确
$condition = "username = '{$_POST['username']}'";
$user = new userModel;
$row = $user->getOne($condition);
if($row){
if($row['password']==md5($_POST['password'])){
//session_start(); 在Application.class.php中统一调用
$_SESSION['u'] = $row;
header('location:index.php?c=index&m=index');
} else{
//die('密码不匹配');
Tool::msg('密码不匹配',5);
}
}else{
//die('用户不存在');
Tool::msg('用户不存在',5);
}
}else{
Tool::msg('验证码不正确',5);
}
}}
?>
<?php
class yzm{
public $len = 4;
public $width = 90;
public $height =25;
public $string = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
protected function sj($number = 4){
$number = intval($number)<=0?4:intval($number);
$number = $number>10?10:$number;
$string = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$stringArray = str_split($this->string);
$stringArray = array_flip($stringArray);
$result = array_rand($stringArray,$number);
$str = ''; //将随机取出的所有值去除赋给一个新的量:$str
foreach($result as $v){
$str.=$v;
}
setcookie('yzm',md5(strtoupper($str)),time()+180);
return $str;//返回验证码给函数
}
public function out(){
$width = 90;
$height = 25;
$img = imagecreate($this->width,$this->height); $black = imagecolorallocate($img,0,0,0); $text = imagecolorallocate($img,255,255,255);//分配白色(定义的颜色) for($i=0;$i<100;$i++){
imagesetpixel($img,mt_rand(0,$this->width),mt_rand(0,$this->height),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255))); if($i%50==0)imageline($img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
$str = $this->sj($this->len); for($i=0;$i<$this->len;$i++){
imagechar($img,5,20*$i+15,5,substr($str,$i,1),imagecolorallocate($img,mt_rand(0,250),mt_rand(0,250),mt_rand(50,200))); } header("Content-Type:image/png");
imagepng($img);
}
}
$a = new yzm();
$a->len = 4;
$a->out();
?>
print_r($_COOKIE);时候,输出
Array ( [PHPSESSID] => 7rpor1tugvmu2dpcrfsqil8lv1 )login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0037)http://localhost:8008/admin/Login.asp -->
<HTML><HEAD><TITLE>企业管理系统后台登陆</TITLE>
<SCRIPT language=javascript>
<!--
function SetFocus()
{
if (document.Login.UserName.value=="")
document.Login.UserName.focus();
else
document.Login.UserName.select();
}
/*function CheckForm()
{
if(document.Login.UserName.value=="")
{
alert("请输入用户名!");
document.Login.UserName.focus();
return false;
}
if(document.Login.Password.value == "")
{
alert("请输入密码!");
document.Login.Password.focus();
return false;
}
if (document.Login.CheckCode.value==""){
alert ("请输入您的验证码!");
document.Login.CheckCode.focus();
return(false);
}
}*/
//-->
</SCRIPT><META content="text/html; charset=gb2312" http-equiv=Content-Type><!-- 调用CSS,JS --><STYLE type=text/css>BODY {
BACKGROUND-IMAGE: url(login1_08.gif); LINE-HEIGHT: 1.5; BACKGROUND-COLOR: #bbd9f5; MARGIN-TOP: 0px; BACKGROUND-REPEAT: repeat-x; FONT-FAMILY: "宋体"; MARGIN-BOTTOM: 0px; COLOR: #546d87; MARGIN-LEFT: 0px; FONT-SIZE: 12px; FONT-WEIGHT: normal
}
</STYLE><META name=GENERATOR content="MSHTML 8.00.6001.19190"></HEAD>
<BODY>
<TABLE border=0 cellSpacing=0 cellPadding=0 width=990 align=left height=650>
<TBODY>
<TR>
<TD vAlign=top width=318>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299 align=right><IMG
src="{$sty->template_dir}/images/login1_01.gif" width=318
height=299></TD></TR>
<TR>
<TD height=351 align=right><IMG
src="{$sty->template_dir}/images/login1_04.gif" width=318
height=351></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=366>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299
background="{$sty->template_dir}/images/login_6.gif" > </TD></TR>
<TR>
<TD height=96 vAlign=top background="{$sty->template_dir}/images/login_9.gif" no-repeat>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=25 width="25%"> </TD>
<TD vAlign=top width="48%">
<FORM onSubmit="return CheckForm();" method=post name=Login action="index.php?c=login&m=login" target=_parent><LABEL><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="username" type="text" id="username" class=txt> </LABEL></TD>
<!-- id=UserName class=txt tabIndex=1 name=UserName> </LABEL></TD>-->
<TD rowSpan=3 width="27%"><INPUT border=0
src="{$sty->template_dir}/images/login_2.gif" width=57 height=55
type=image></TD></TR>
<TR>
<TD height=25> </TD>
<TD><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="password" type="text" id="password" class="txt"/>
<!-- id=password class=txt tabIndex=2 type=password name=Password> -->
</TD></TR>
<TR>
<TD height=25> </TD>
<TD><INPUT
style="BORDER-BOTTOM: #000000 1px double; BORDER-LEFT: #000000 1px double; HEIGHT: 22px; FONT-SIZE: 13px; BORDER-TOP: #000000 1px double; FONT-WEIGHT: bold; BORDER-RIGHT: #000000 1px double"
name="yzm" type="text" id="yzm" class="yzm" />
<!-- id="checkcode" tabIndex=300 size=12 name="checkcode" /> -->
<IMG style="margin-top:6px;"
src="../Core/yzm.class.php" width="156" height="60" onclick="this.src='../Core/yzm.class.php?id='+Math.random();" style="cursor:pointer" alt="看不清,请点击更换" title="看不清,请点击更换"/> </TD></TR></FORM></TBODY></TABLE></TD></TR>
<TR>
<TD height=255 background="{$sty->template_dir}/images/login1_07.gif">
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD
height=129> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=318>
<TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD height=299 background="{$sty->template_dir}/images/login1_03.gif"
align=left> </TD></TR>
<TR>
<TD height=351 background="{$sty->template_dir}/images/login1_06.gif "
align=left> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<SCRIPT language=JavaScript type=text/JavaScript>
CheckBrowser();
SetFocus();
</SCRIPT></BODY>
</HTML>
<?php
class loginAction extends Action{ function login(){
print_r($_COOKIE);
print_r($_POST);
exit;
if(md5(strtoupper($_POST['yzm']))==$_COOKIE['yzm']){//如果验证码正确
$condition = "username = '{$_POST['username']}'";
$user = new userModel;
$row = $user->getOne($condition);
if($row){
if($row['password']==md5($_POST['password'])){
//session_start(); 在Application.class.php中统一调用
$_SESSION['u'] = $row;
header('location:index.php?c=index&m=index');
} else{
//die('密码不匹配');
Tool::msg('密码不匹配',5);
}
}else{
//die('用户不存在');
Tool::msg('用户不存在',5);
}
}else{
Tool::msg('验证码不正确',5);
}
}}
?>
<?php
class yzm{
public $len = 4;
public $width = 90;
public $height =25;
public $string = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
protected function sj($number = 4){
$number = intval($number)<=0?4:intval($number);
$number = $number>10?10:$number;
$string = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$stringArray = str_split($this->string);
$stringArray = array_flip($stringArray);
$result = array_rand($stringArray,$number);
$str = ''; //将随机取出的所有值去除赋给一个新的量:$str
foreach($result as $v){
$str.=$v;
}
setcookie('yzm',md5(strtoupper($str)),time()+180);
return $str;//返回验证码给函数
}
public function out(){
$width = 90;
$height = 25;
$img = imagecreate($this->width,$this->height); $black = imagecolorallocate($img,0,0,0); $text = imagecolorallocate($img,255,255,255);//分配白色(定义的颜色) for($i=0;$i<100;$i++){
imagesetpixel($img,mt_rand(0,$this->width),mt_rand(0,$this->height),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255))); if($i%50==0)imageline($img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
$str = $this->sj($this->len); for($i=0;$i<$this->len;$i++){
imagechar($img,5,20*$i+15,5,substr($str,$i,1),imagecolorallocate($img,mt_rand(0,250),mt_rand(0,250),mt_rand(50,200))); } header("Content-Type:image/png");
imagepng($img);
}
}
$a = new yzm();
$a->len = 4;
$a->out();
?>
session_start(); //加下这个试下
class loginAction extends Action{function login(){
print_r($_COOKIE);
print_r($_POST);
exit;
获取session值是echo $_SESSION['session名称']这样写啊,你$_COOKIE输出的值是你MD5加密后的值
问题已经解决了,谢谢大家的支持,$_COOKIE的作用域问题
setcookie('yzm',md5(strtoupper($str)),time()+180,'/');
这样就好了