I want to stop direct access to controller functions or views in Codeigniter for that i am using following code, I have seen other similar links on stackoverflow but they are not working, i am able to load the view by hitting 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>
NO. You are completely wrong. We newer use this in view
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
Every one can see your controller/method
(abc/Create_Course
) name but no one knows about your view name without viewing your project. So there is no any purpose to hide or restrict view from others.
There is no way to access view folder from URL. if assume some how some one access this then also no one knows your folder names. so this warning message shows in browser.
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>