简体   繁体   中英

ignoring frontpage.php in codeigniter

I'm currently working on an existing website created in codeigniter. Whenever a user enters a page, he gets redirected to frontpage.php, that checks if the user is logged in, if not he gets redirected to the login page. Now, I have one page where this frontpage.php shouldnt be executed, and any user can enter it.

Any help is greatly appreciated.

Had a similar problem and solved it this way by using some online tutorials

1: Make a seperate loginpage (ex login.php) prior to the 'frontpage.php'.

2: Pass the login, password and a session variable to the frontpage.

3: Recode you 'frontpage.php' to check for the session variable passed by 'login.php'.

If u entered the page trough the normal way it will use the normal login. if u entered the page trough the new 'login.php' page it will be picked up by the recoded 'frontpage.php' and bypass the normal way.

Hope this helps

Grtz

make new controller

class Newpage extends CI_Controller {

  public function index(){
    $this->load->view('newpage');
  }
}

now goto

yourhost.com/index.php/newpage

May be your default Controller have a coding of checking whether user is logged or not. Please remove or change the code in controller.

我认为您需要删除控制器,它的工作原理是这样的!

Re-route everything to your pages controller and use this as your default

$route['default_controller'] = 'pages';

$route['(.*)'] = 'pages/index/$1';

-

class Pages extends CI_Controller
{
    protected $currentUser = null;

    public function __construct()
    {
        parent::__construct();
        $this->currentUser = Auth::getCurrentUserObject(); //check user is logged in
    }

    public function index($uri='home')
    {

        $sizeOfSegments = sizeof($this->uri->rsegments);

        if ($sizeOfSegments >= 3)
        {       
            $uri = $this->uri->rsegments[3];
        } 
        else
        {
            $uri = 'home';
        }

        $pageFound = Page::find($uri); //query the database

        if (!$pageFound)
        {
            return show_404($uri); // find out where there were headed 
        }

        unset($sizeOfSegments, $uri);

        if(is_null($this->currentUser) OR !$this->currentUserHasPermissionToViewThisPage OR !$pageIsNotPublic)
        {
            return redirect('login');
        }

        $this->load->view();

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM