Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » BackURL redirect from base page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 296 Views
  • SideShow
    Avatar
    Community Member
    3 Posts

    BackURL redirect from base page Link to this post

    When my users first go to the website, they use the URL http://www.example.com and they are redirected to http://www.example.com/index.php/Security/login?BackURL=%2F, if they try to login, they are redirected back to that same page.

    My login form has the following code that refers to the BackURL:

          if (isset($_REQUEST['BackURL'])) {
             $backURL = $_REQUEST['BackURL'];
          } else {
             $backURL = Session::get('BackURL');

    If I click on the logo, the page refreshes and takes me to http://www.example.com/index.php/Security/login?BackURL=%2Findex.php%2F and then they can login successfully. Is there any way to fix it so when they enter http://www.example.com, they are taken to http://www.example.com/index.php/Security/login?BackURL=%2Findex.php%2F. I feel like I’m missing an if\then statement that would be the catchall for when they go to the root and don’t enter the index.php.

    I'm new to PHP and web development in general, but it seems to me there should be a way to say if the BackURL variable is null then backurl=index.php

  • Tim Snadden
    Avatar
    Community Member
    32 Posts

    Re: BackURL redirect from base page Link to this post

    You shouldn't need to create your own login form. If the user doesn't have permission to view a particular part of the site they should get directed to Security/login with a BackUrl set to where they came from. Once they have logged in they should be shown the content. Try putting something like this in your Page class (or some other permission check). Make sure that your template includes $Form.

       public function canView($member = null) {
          return Permission::check('SITETREE_VIEW');
       }

    296 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.