为什么我的网站登录页在本地测试可以正常登录,在服务器却无法正常跳转呢?
<form action="{:U('Login/login')}" method="post"> <ul> <li><img src="__PUBLIC__/frontend/images/login_name_bg.gif" alt="" title="用户名"/> <input type="text" class="denglu_srk" placeholder="用户名/邮箱/手机号" value="<?php echo $_COOKIE['username'];?>" name="name" style=" float:left"/> </li> <li><img src="__PUBLIC__/frontend/images/login_password_bg.gif" alt="" title="密码"/> <input type="password" class="denglu_srk" placeholder="密码" onpaste="return false" name="pass" id="pass_id" style=" float:left"/> </li> <?php if($_SESSION['login_time']>=3):?> <li><input placeholder="输入验证码" class="yanzhengma" name="verify"/><img class="verify-code" src="{:U('Register/verify')}" onClick="click_change(this)" style=" margin-left:10px; vertical-align:middle;" title="验证码"/><b id="verify1"></b></li> <?php endif;?> </ul> <p><a href="{:U('FindPass/email')}">忘记密码?</a><a href="{:U('Register/index')}">免费注册</a></p> <div class="denglu_but_con"><input class="denglu_but" type="submit" value=" "/></div> </form>
LoginAction.class.php的代码:
...class LoginAction extends GlobalAction { public function _initialize() { parent::_initialize(); if (isset($_SESSION['uid']) && $_SESSION['uid'] && strtolower(ACTION_NAME) != 'logout') { $this->redirect("Usercontent/index"); } } /** * 显示登陆界面 */ public function index() { $back = $_SERVER['HTTP_REFERER']; if (!$back || strpos(strtolower($back), 'login') !== false || strpos(strtolower($back), 'register') !== false) { $back = U('Usercontent/index'); } $_SESSION['back'] = $back; $this->display(); } /** * 处理用户登陆 */ public function login() { $username = I("post.name", '', 'trim'); $password = I("pass", '', 'fix_pass'); $c_username = $_COOKIE['username']; if ($c_username != $username) { setcookie('username', $username); } $_SESSION['login_time'] = intval($_SESSION['login_time']) + 1; if ($_SESSION['login_time'] > 3 && md5(I('verify', '', 'strtolower')) != $_SESSION['verify']) { $this->forword('验证码错误!'); } if (I("name") == null || I("pass") == null) { $this->forword('用户名或密码不能为空'); } $map["u_username|u_email|u_phone"] = $username; $map["u_password"] = $password; $user = M("user")->where($map)->find(); $this->doLogin($user); } /** * 执行登陆 * * @param type $user */ public function doLogin($user) { if (!empty($user)) { if ($user['u_status'] != 1) { $this->forword('用户已经被冻结'); } //检查是否在异地登陆 if ($this->checkedRemoteLogin($user['id'])) { $this->forword('请不要重复登陆!'); } $this->bind($user['id']); $logId = $this->logLogin($user); $user['logId'] = $logId; $this->setSession($user); unset($_SESSION['login_time']); unset($_SESSION['errorMsg']); $back = $_SESSION['back']; unset($_SESSION['back']); if (!$back) { $back = U('Usercontent/index'); } if (strpos(strtolower($back), 'eintro') !== false) { $back = U('Fund/asset'); } if (!$back || strpos(strtolower($back), 'login') !== false || strpos(strtolower($back), 'register') !== false) { $back = U('Usercontent/index'); } header("Location:" . $back); } else { $this->forword('用户名或密码错误'); } } /** * 绑定第三方平台 */ public function bind($uid) { $status3 = true; if ($_SESSION['thirdPartyUserId'] && !A('Register')->hasBind($_SESSION['thrid_party_type'])) { $data['uid'] = $uid; $data['third_party_id'] = $_SESSION['thirdPartyUserId']; $data['type'] = $_SESSION['thrid_party_type']; $status3 = M('third_party_bind')->add($data); unset($_SESSION['thirdPartyUserId']); unset($_SESSION['thrid_party_type']); } return $status3; } /** * 记录登陆日志 * * @param array $user * @return type */ protected function logLogin(array $user) { $login = D('Login')->insertLogin($user); return $login['insert_id']; } /** * 设置登陆SESSION * * @param type $user */ protected function setSession($user) { $_SESSION["username"] = $user["u_username"]; $_SESSION["uid"] = $user["id"]; $_SESSION["login_time"] = time(); $_SESSION['online_time'] = time(); $_SESSION['logId'] = $user['logId']; }...
url 重写没有生效
url 重写没有生效
<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]</IfModule>
本地是windows7 32位+php now环境
服务器是LINUX+wdcp服务器/虚拟主机管理系统
还可能是 session 无效
问题查出来了,是控制器的最后一句语句不起作用:
header("Location:" . $back);
而$back = ‘/usercontent-index.html’
这个语句不知怎的在本地可以跳转,在网站上却不行
改成这样也不行啊:
$strs = explode('.',$back); $this->redirect($strs[0]);
if (!$back) { $back = U('Usercontent/index'); } if (strpos(strtolower($back), 'eintro') !== false) { $back = U('Fund/asset'); } if (!$back || strpos(strtolower($back), 'login') !== false || strpos(strtolower($back), 'register') !== false) { $back = U('Usercontent/index'); }
不对!
http://www.onloan.com.cn/usercontent-index.html
会转到
http://www.onloan.com.cn/login-index.html
所以要么是登录程序有问题(无法确认是用户),要么是 session 失效
session保存目录可写?
fwrite($fp,'username: ',$_SESSION['username']); 这句无法输出
session保存目录可写?
session保存目录可写?
大麦加油!关注、学习!
\ThinkPHP\Common\functions.php
$name['path'] = "/Runtime"; //thinkphp目录下if(isset($name['path'])) session_save_path($name['path']);
楼上这样设本地都无法登录了,
晕死,是PHP版本的问题,以下同样的代码,本地返回true,服务器返回false,
跟踪结果,同样是SESSION为空
protected function isLogin() {if (!empty($_SESSION['username']) && !empty($_SESSION['uid'])) { $this->updateOnlineTime(); return true; } else { return false; }}
$fp = fopen('./qerr26.txt','w+'); fwrite($fp,'ok'); session_start(); $_SESSION['XXX'] ='123'; fwrite($fp,'SESSIONXXX: ',$_SESSION['XXX']); fwrite($fp,'username: ',$_SESSION['username']); fwrite($fp,'uid: ',$_SESSION['uid']); fclose($fp);
也可能是你的服务器 php 版本低了
$url = 'http://www.onloan.com.cn/usercontent-index.html';print_r(get_headers($url));echo file_get_contents($url);
Array( [0] => HTTP/1.1 200 OK [1] => Date: Sun, 05 Oct 2014 05:57:52 GMT [2] => Content-Type: text/html [3] => Content-Length: 265 [4] => Connection: close [5] => Server: nginx/1.0.15 [6] => X-Powered-By: PHP/5.2.17p1)<head><meta property="qc:admins" content="147026777767647166375636" /><meta property="qc:admins" content="4716300527622221636375" /><meta property="qc:admins" content="471630043674556654" /></head><meta http-equiv='Refresh' content='0;URL=/login-index.html'>
再有,你的服务器用的是 nginx
能支持 .htaccess 吗?
再有,你的服务器用的是 nginx
能支持 .htaccess 吗?
你在登录页打印一下传入的参数看看
这样无目标的瞎猜是没有用的
你在登录页打印一下传入的参数看看
这样无目标的瞎猜是没有用的
$map["u_username|u_email|u_phone"] = $username; $map["u_password"] = $password; $user = M("user")->where($map)->find(); $fp = fopen('./qerr28.txt','w+'); fwrite($fp,'username: ',$user["u_username"]); fwrite($fp,'uid: ',$user["id"]); fclose($fp);
我不知道到哪里看TRACE的跟踪信息,在哪个目录的哪个日志文件里?
20楼的代码有错,更正为:
$map["u_username|u_email|u_phone"] = $username; $map["u_password"] = $password; $user = M("user")->where($map)->find(); $fp = fopen('./qerr28.txt','w+'); fwrite($fp,' username: ' . $user["u_username"]); fwrite($fp,' uid: ' . $user["id"]); fclose($fp);
protected function isLogin() { //cjq add $fp = fopen('./qerr26.txt','w+'); fwrite($fp,'ok'); $_SESSION['XXX'] ='123'; fwrite($fp,' SESSIONXXX: ' . $_SESSION['XXX']); fwrite($fp,' username: ' . $_SESSION['username']); fwrite($fp,' uid: ' . $_SESSION['uid']); fclose($fp);
php.ini 中 session.auto_start 的值是什么?
保存session的变量没有成功,有可能是php版本问题,对于session 环境参数设置可能不一样,通过php5.0 php5.2对比session环境变量参数。
php.ini 中 session.auto_start 的值是什么?
相対パスの問題?
いいえ