我有一个问题,我的CodeIgniter控制器被调用两次.它似乎只发生在我使用uri中的参数时(/ newsletter/confirm/a1938cas893vf9384f0384f0943).如果我从我的函数中删除参数,它只加载一次控制器.我还注意到,使用url中的参数,如果我刷新页面,它只加载一次.因此,只有在调用新页面时才会加载两次.
例如,第一次导航到/ newsletter/confirm/a123将导致加载两次.但如果您要刷新/ newsletter/confirm/a123,它只会加载一次.我已完成对我的视图的注释,以消除引起它的视图的问题.
这听起来像是缓存问题,还是我的.htaccess文件中的某些内容?谢谢你的任何建议.
相关控制人:
<?php
error_reporting(-1);
ini_set('display_errors',1);
class Test extends CI_Controller {
function __construct() {
parent::__construct();
log_message('debug', 'MyController initialised');
}
function confirm($code)
{
$this->load->helper(array('form'));
//$code = "6e930fe882c3b15712158812769dbcb636f96b8c";
$result = $this->db->get_where('newsletter_members', array('nm_confirmation_code' => $code, 'nm_subscribed' => 0));
if ($result->num_rows == 0)
{
$newsletter_message['newsletter_message'] = "Confirmation code is invalid or has already been confirmed.";
//$this->load->view('index_test', $newsletter_message);
} else {
$newsletter_message['newsletter_message'] = "Thank you for confirming your intent to subscribe to our newsletter!";
$data = array(
'nm_subscribed' => 1,
);
$this->db->where('nm_confirmation_code', $code);
$this->db->update('newsletter_members', $data);
//$this->load->view('index_test', $newsletter_message);
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
.htaccess文件:
RewriteEngine On
RewriteCond $1 !^([^\..]+\.php|robot\.txt|public|images|css|js|paul|event_docs|blog|citeforme|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
# BEGIN WordPress
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
#</IfModule>
#RewriteEngine Off
# END WordPress
Run Code Online (Sandbox Code Playgroud)
这是日志文件的样子,您可以看到所有内容都被重新加载两次:
DEBUG - 2011-09-16 09:59:34 --> Config Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Hooks Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Utf8 Class Initialized
DEBUG - 2011-09-16 09:59:34 --> UTF-8 Support Enabled
DEBUG - 2011-09-16 09:59:34 --> URI Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Router Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Output Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Input Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Global POST and COOKIE data sanitized
DEBUG - 2011-09-16 09:59:34 --> Language Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Loader Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Database Driver Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Controller Class Initialized
DEBUG - 2011-09-16 09:59:34 --> MyController initialised
DEBUG - 2011-09-16 09:59:34 --> Helper loaded: form_helper
DEBUG - 2011-09-16 09:59:34 --> Final output sent to browser
DEBUG - 2011-09-16 09:59:34 --> Total execution time: 0.0223
DEBUG - 2011-09-16 09:59:34 --> Config Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Hooks Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Utf8 Class Initialized
DEBUG - 2011-09-16 09:59:34 --> UTF-8 Support Enabled
DEBUG - 2011-09-16 09:59:34 --> URI Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Router Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Output Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Input Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Global POST and COOKIE data sanitized
DEBUG - 2011-09-16 09:59:34 --> Language Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Loader Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Database Driver Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Controller Class Initialized
DEBUG - 2011-09-16 09:59:34 --> MyController initialised
DEBUG - 2011-09-16 09:59:34 --> Helper loaded: form_helper
DEBUG - 2011-09-16 09:59:34 --> Final output sent to browser
DEBUG - 2011-09-16 09:59:34 --> Total execution time: 0.0213
Run Code Online (Sandbox Code Playgroud)
通常这是由"脏"模板造成伪造的CSS,Javascript和图像调用引起的.
最好通过仔细检查模板中的所有资产调用来防止这种情况发生,但是如果其他人正在执行有时不可选的模板.
这是我在那种情况下所做的:
检查HTTP_REFERRER是否与REQUEST_IRI相同.如果是这样,您知道它是从当前加载的同一页面调用的内容,因此您对丢失的资产进行了虚假调用.
如果控制器(此代码也适用于index.php入口点文件),我将以下代码放在顶部.
$self_referrer = $_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == $self_referrer){
return; // no point in going further since this is a bogus call...
}
Run Code Online (Sandbox Code Playgroud)
我不知道这是否是您的 .htaccess 文件,但我已经使用它一段时间了,从未遇到过问题:
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
我想说,首先更改文件,看看是否可以解决问题,另外,请确保在 config.php 文件中,index_page 变量为空,如下所示:
$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
另一件事,您是否在routes.php 文件中定义了任何路由?也许它们导致了一些奇怪的循环,导致页面加载两次。
| 归档时间: |
|
| 查看次数: |
3790 次 |
| 最近记录: |