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.

Customising the CMS /

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

Check member logged in on extarnal file / protect external php file inside Silverstripe.


Go to End


5 Posts   1192 Views

Avatar
programmerswe

Community Member, 8 Posts

29 September 2015 at 10:34pm

So, basically I got a php file containing some information and so on. This site is accessable in the url even tho the user is not logged in to Silverstripe. Is there any special folder in which i can put this php file so a user need to sign in before accessing it. This is just a regular php file that i wrote myself. Or is there any speciel php check that i can use to see however an user is logged in?

Cheers

Avatar
Devlin

Community Member, 344 Posts

1 October 2015 at 1:29am

Edited: 01/10/2015 1:57am

Or is there any speciel php check that i can use to see however an user is logged in?

You could check in your php file if $_SESSION['loggedInAs'] is not empty or otherwise exit the script.

session_start();
if (empty($_SESSION['loggedInAs'])) {
	//header('Location: http://mydomain.com/Security/login');
	exit;
}
// continue with some information

On the other hand, it is more reasonable to completely yield to how things are done in a framework. The information you want to provide to authenticated users should be returned by a controller which responds to a route.

Avatar
programmerswe

Community Member, 8 Posts

1 October 2015 at 8:18pm

Yeah, i wanted to user this module at first, but it didn't support the PhP files and i wasn't able to extend the allowed types in any of the _config files.
https://github.com/silverstripe-labs/silverstripe-secureassets

Avatar
Devlin

Community Member, 344 Posts

1 October 2015 at 9:02pm

Oh, it's possible with the secureassets module. But you should not use it for this, because there should not be any php scripts inside a upload directory. There is simply no reason for doing this or bad things will happen.

The only correct way to do this is with a controller.

https://docs.silverstripe.org/en/3.1/developer_guides/controllers/introduction/

Avatar
programmerswe

Community Member, 8 Posts

1 October 2015 at 10:35pm

That's true.