Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

BackURL redirect from base page


Go to End


2 Posts   2107 Views

Avatar
SideShow

Community Member, 3 Posts

13 May 2014 at 1:01pm

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

Avatar
Tim Snadden

Community Member, 32 Posts

15 May 2014 at 8:42pm

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');
	}