Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何限制只允许登录用户使用的目录:Codeigniter_Php_Codeigniter_Redirect - Fatal编程技术网

Php 如何限制只允许登录用户使用的目录:Codeigniter

Php 如何限制只允许登录用户使用的目录:Codeigniter,php,codeigniter,redirect,Php,Codeigniter,Redirect,我的项目中有一个根目录,在应用程序文件夹的外面,如下所示。 localhost/my\u项目/my\u目录 因此,我如何保护我的_目录,只有登录的用户才能访问此目录,如果任何人未登录并直接访问此目录,它将重定向到localhost/my_项目“主页” 我使用过这种方法,但不起作用: <?php if(!$this->session->userdata('logged_in')) || $this->uri->segment(1) == 'my_directory'

我的项目中有一个根目录,在应用程序文件夹的外面,如下所示。 localhost/my\u项目/my\u目录 因此,我如何保护我的_目录,只有登录的用户才能访问此目录,如果任何人未登录并直接访问此目录,它将重定向到localhost/my_项目“主页”

我使用过这种方法,但不起作用:

<?php if(!$this->session->userdata('logged_in'))  || $this->uri->segment(1) == 'my_directory'){
           redirect('homepage')
     }

看起来您可能有一个额外的并且需要一个

<?php if(!$this->session->userdata('logged_in') || 
         $this->uri->segment(1) == 'my_directory') {
           redirect('homepage');
     }
我想你想做什么就做什么

你要在oldDirectory中创建.htaccess文件吗

//301 Redirect Entire Directory
RedirectMatch 301 /oldDirectory(.*) /NewDirectory/$1
我认为您可以使用阻止访问所需的目录重命名oldDirectory,并将NewDirectory重命名为登录表单(我猜:)


你可以通过文件看到,但实际上我不知道该把代码放在哪里。在控制器中,我必须创建一个方法,然后我将如何触发该方法。这就是问题所在@user2182349@ShoaibFareed-此代码将放入控制器或其扩展。我想这会有所帮助