无法使用基本路径限制对 Codeigniter 中视图和函数的直接访问
Cannot restrict direct access to views and functions in Codeigniter using basepath
我想停止直接访问 Codeigniter 中的控制器功能或视图,因为我正在使用以下代码,我在 Whosebug 上看到了其他类似的链接,但它们不起作用,我可以通过点击 url:
Controller: abc.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
Class Abc extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function Create_Course() {
$this->load->view('abc');
}
}
?>
View: abc.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<html>
<head>
<title>ABC</title>
</head>
<body>
<h1>Whatever</h1>
</body>
</html>
没有。你完全错了。我们最近在 view
中使用了这个
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
每个人都能看到你的controller/method
(abc/Create_Course
) 名称,但 没有人在不查看您的项目的情况下知道您的视图名称。因此,没有任何目的可以隐藏或限制他人查看。
无法从 URL 访问视图文件夹。如果假设某些人如何访问它,那么也没有人知道您的文件夹名称。所以此警告消息显示在浏览器中。
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
根据 Codeigniters 文档,您需要在控制器中的函数名称前加上下划线,如下所示:
private function _utility()
{
// some code
}
这非常适合自定义规则,例如表单验证或您希望在控制器中使用但无法通过浏览器使用的任何其他内容 url。我认为这就是您要找的。
我想停止直接访问 Codeigniter 中的控制器功能或视图,因为我正在使用以下代码,我在 Whosebug 上看到了其他类似的链接,但它们不起作用,我可以通过点击 url:
Controller: abc.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
Class Abc extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function Create_Course() {
$this->load->view('abc');
}
}
?>
View: abc.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<html>
<head>
<title>ABC</title>
</head>
<body>
<h1>Whatever</h1>
</body>
</html>
没有。你完全错了。我们最近在 view
中使用了这个<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
每个人都能看到你的controller/method
(abc/Create_Course
) 名称,但 没有人在不查看您的项目的情况下知道您的视图名称。因此,没有任何目的可以隐藏或限制他人查看。
无法从 URL 访问视图文件夹。如果假设某些人如何访问它,那么也没有人知道您的文件夹名称。所以此警告消息显示在浏览器中。
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
根据 Codeigniters 文档,您需要在控制器中的函数名称前加上下划线,如下所示:
private function _utility()
{
// some code
}
这非常适合自定义规则,例如表单验证或您希望在控制器中使用但无法通过浏览器使用的任何其他内容 url。我认为这就是您要找的。