If the THINKPHP website logon page is tested locally, you can log on normally, but cannot jump to the server.

Source: Internet
Author: User
The THINKPHP website logon page can be used for normal logon in the local test, but cannot be redirected to the server. Why can I log on to the logon page in the local test but cannot be redirected to the server?
 



Reply to discussion (solution)

LoginAction. class. php code:

... Class LoginAction extends GlobalAction {public function _ initialize () {parent: _ initialize (); if (isset ($ _ SESSION ['uid']) & $ _ SESSION ['uid'] & strtolower (ACTION_NAME )! = 'Logout') {$ this-> redirect ("Usercontent/index") ;}}/*** display logon interface */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 ();} /*** process User login */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 ', '', 'strlower '))! = $ _ SESSION ['verify ']) {$ this-> forword ('verification code error! ');} If (I ("name") = null | I ("pass") = null) {$ this-> forword ('user name or password cannot be blank ');} $ map ["u_username | u_email | u_phone"] = $ username; $ map ["u_password"] = $ password; $ user = M ("user")-> where ($ map)-> find (); $ this-> doLogin ($ user);}/*** execute logon ** @ param type $ user */public function doLogin ($ user) {if (! Empty ($ user) {if ($ user ['U _ status']! = 1) {$ this-> forword ('User frozen ');} // check whether remote logon is performed if ($ this-> checkedRemoteLogin ($ user ['id']) {$ this-> forword ('do not log on again! ') ;}$ 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), 'Intro ')! = 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 ('user name or password error');}/*** bind to a third-party platform */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 ;} /*** log logon ** @ param array $ user * @ return type */protected function logLogin (array $ user) {$ login = D ('login ') -> insertLogin ($ user); return $ login ['Insert _ id'];} /*** set the login 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 rewriting does not take effect

Url rewriting does not take effect



Well, why didn't it take effect? Other pseudo-static actions take effect.

. Htaccess file:
 
  RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
 

Windows 7 32-bit + php now Environment
The server is a LINUX + wdcp server/virtual host management system.

It may also be that the session is invalid.

The problem is found, and the last statement of the controller does not work:
Header ("Location:". $ back );
And $ back = '/usercontent-index.html'
This statement can be redirected locally, but not on the website.

It cannot be changed like this:

$strs = explode('.',$back);   $this->redirect($strs[0]);  


Previous code:
 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');            }


No!
Http://www.onloan.com.cn/usercontent-index.html
Will go
Http://www.onloan.com.cn/login-index.html

Therefore, either the logon program is faulty (the user cannot be confirmed) or the session is invalid.

Can the session save directory be written?

Fwrite ($ fp, 'username: ', $ _ SESSION ['username']); this sentence cannot be output.

Can the session save directory be written?



In what directory is the session stored?

Can the session save directory be written?



Session. save_path = "/tmp"
/Tmp permission is drwxrwxrwt
I cleared the/tmp directory and restarted the server.

Barley! Follow and learn!

\ ThinkPHP \ Common \ functions. php

$ Name ['path'] = "/Runtime"; // if (isset ($ name ['path']) in the thinkphp directory) session_save_path ($ name ['path']);


Is this correct?

In this way, no local logon is available,

Dizzy, it is a PHP version problem. The following code returns true locally and false on the server,
The trail result. The SESSION is also empty.

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); 


The result is:
OkSESSIONXXX: uid:
Strange, username: no output

It may be that your php version is too low.

$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)
 
 
 
 

In addition, your server uses nginx
Can. htaccess be supported?

In addition, your server uses nginx
Can. htaccess be supported?



The server supports. htaccess.

My local PHP version is 5.0, and debugging and login is OK
The PHP version on the server is 5.2. how can I change the code? Thank you!

Print the input parameters on the logon page.
It is useless to guess without a goal.

Print the input parameters on the logon page.
It is useless to guess without a goal.



Thank you, moderator,

        $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); 


The output content of supervisor and server qerr28.txt is only:
Uid:

How can this M method be further tracked?

I don't know where to view TRACE information. in which Directory is the log file?

The code on the 20th floor is incorrect. correct it:

 $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); 


Both the worker and the server qerr28.txt output:
$ User: Array username: mikeccn uid: 4

In BaseAction. class. php:
    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); 

Qerr26.txt output:
OK SESSIONXXX: 123 username: mikeccn uid: 4
Server qerr26.txt output:
OK SESSIONXXX: 123 username: uid:
Why? What is the cause of cross-page SESSION loss on the server? (Local cross-page SESSION is not lost)

In php. ini, what is the value of session. auto_start?

Failed to save the session variable, which may be a php version issue. The session environment parameter settings may be different. compare the session environment variable parameters through php5.0 php5.2.

In php. ini, what is the value of session. auto_start?



The session. auto_start = 0 is changed to 1 and it is OK. thank you very much!

Relative path problems?
No

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.