简体   繁体   中英

CodeIgniter controllers being called twice

It is entirely possible that I've made a huge mistake someplace, but for some reason, my controllers are being called twice. This is breaking DX_Auth's captcha's on Chrome, but somehow, Firefox and IE can handle it.

The problem is, every controller is getting called twice milliseconds apart. I used log_message() to print every key/value pair from the $_SERVER superglobal.

The only differences are:

1st Call

'HTTP_CACHE_CONTROL' => 'max-age=0'
'HTTP_ACCEPT' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
'HTTP_COOKIE' => 'ci_session=a:4:{s:10:"session_id";s:32:"4be9cef4e2cdae468c7443f52a5fb3f2";s:10:"ip_address";s:13:"321.321.321.321";s:10:"user_agent";s:50:"Mozilla/5.0+(Windows;+U;+Windows+NT+6.1;+en-US)+Ap";s:13:"last_activity";s:10:"1282151409";}70b300096c8d40c60a676ac65bcb222c'
'REMOTE_PORT' => '61828'

and the 2nd Call

'HTTP_CACHE_CONTROL' => NULL
'HTTP_ACCEPT' => '*/*'
'HTTP_COOKIE' => 'ci_session=a:4:{s:10:"session_id";s:32:"a5bb2c98a8ff4438cef3a3fe3d5ff73e";s:10:"ip_address";s:13:"321.321.321.321";s:10:"user_agent";s:50:"Mozilla/5.0+(Windows;+U;+Windows+NT+6.1;+en-US)+Ap";s:13:"last_activity";s:10:"1282151734";}4adf1de21f9708d66b3d4bc36d0b0d92'
'REMOTE_PORT' => '61842'

There is a thread already on the CI forums where someone else had a similar problem, but his problem turned out to be spyware. This is not the case for me. I tried on several computers and none of my visitors can register for the site.

You see, DX_auth stores the value of the captcha as CI session flashdata on the first call. The second call wipes the flashdata and no one can ever get the captcha correct as a result.

Here is a sample of my access logs

123.123.123.123 - - [18/Aug/2010:12:31:26 -0500] "GET /welcome HTTP/1.1" 200 3391 "http://somewhere.com/[age" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4"
123.123.123.123 - - [18/Aug/2010:12:31:27 -0500] "GET /welcome HTTP/1.1" 200 3391 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4"

As you can see, the first call seems to be coming from me, and the second call has no referrer.

I thought there was a problem with the .htaccess file I used to eliminate index.php from the uri. So, I switched to the "default" .htaccess redirect as stated in the CI documentation. The double load still happens.

RewriteEngine on
RewriteCond $1 !^(index\.php|asset|captcha|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

I also used FireFox's "Live HTTP headers" plugin. It looks like only one request is being sent, but FireBug's console show that two replies are coming back.

Anybody know what's going on? Has this happened to anyone else?

请参阅我对类似问题的回复,以了解导致此问题的原因,以及如何开始识别确切的问题: 控制器操作被调用两次--- Php应用程序

My issue was this and the page being reloaded on this meta tag. Removed it and the Firefox double loading stopped.

<meta http-equiv="Content-Type" content="text/css; charset=utf-8" />

i experience the same problem and that drive me mad. the request is actually come from firefox. the firefox browser send the request twice. so it wasn't codeigniter side error. try to use another version of firefox. it should be fix the problem.

我在基于响应的DOM元素上使用jQuery绑定事件时遇到了这样的行为,忘记了你需要取消绑定该DOM元素上的旧事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM