php codeigniter“不允许直接访问脚本”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25269823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
codeigniter "No direct script access allowed"
提问by ask
even i have added "if ( ! defined('BASEPATH')) exit('No direct script access allowed'); " on top of controller .Actually I need to display data in div my ajax call: below is ajax call which calls Createcaptcha to get data but instead of data it response "No direct script access allowed"
即使我在控制器顶部添加了“if(!定义('BASEPATH'))exit('不允许直接脚本访问');”。实际上我需要在div中显示数据我的ajax调用:下面是ajax调用Createcaptcha 以获取数据,但它响应“不允许直接脚本访问”而不是数据
$(document).ready(function(){
$.ajax({
type: "POST",
url: 'website/Createcaptcha',
success: function(data){
$("#captcha").html(data);
}
});
});
below is controller
下面是控制器
public function Createcaptcha(){
$image = $this->captcha_model->create_image();
echo $image;
}
Response data is displayed in div as "No direct script access allowed" , It works fine on xampp localhost
响应数据在 div 中显示为“不允许直接脚本访问”,它在 xampp localhost 上工作正常
回答by Somnath Paul
Check if your BASEPATH is set in codeigniter. It is set in index.php of root folder. Just echo the BASEPATH and see what it is printed.
检查您的 BASEPATH 是否在 codeigniter 中设置。它在根文件夹的 index.php 中设置。只需回显 BASEPATH 并查看打印的内容。
Find the following in index.php
在 index.php 中找到以下内容
define('BASEPATH', str_replace("\", "/", $system_path));
回答by B2725
Please use
请用
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
in database.phpfile.
在database.php文件中。
回答by PC.
I had a similar problem and for someone who might look for an answer for this issue, my ten cents.
我有一个类似的问题,对于可能为这个问题寻找答案的人,我的十美分。
In basepath website name is set as htts://www.websitename.com and client opened without https (http://www.websitename.com) and also in some cases without www (https://websitename.comor http://websitename.com).
在 basepath 中,网站名称设置为 htts://www.websitename.com 并且客户端打开时没有 https ( http://www.websitename.com),在某些情况下也没有 www ( https://websitename.com或http: //网站名称.com)。
Since either of them do not match to the basepath defined, the request is not honored as ajax request. Solution : ensure that you have proper redirection (http to https & non-www to www).
由于它们中的任何一个都与定义的基本路径不匹配,因此该请求不会被视为 ajax 请求。解决方案:确保您有正确的重定向(http 到 https 和非 www 到 www)。
回答by Bishal Paudel
I replaced <?
with <?php
and everything worked fine because of php settings in server.
由于服务器中的 php 设置,我替换<?
了<?php
并且一切正常。