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.

General Questions

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

What is if($this->basicAuthEnabled) BasicAuth::protect_site_if_necessary();


5 Posts   948 Views

Ryan M.

1 May 2010 at 8:03am Community Member, 309 Posts

What is this?

if($this->basicAuthEnabled) BasicAuth::protect_site_if_necessary();

It's in Controller.php, on line 78. I had to comment this out to get my site working again after it quit working for some strange reason and kept throwing an error related to that function.

Ryan M.

1 May 2010 at 9:15am Community Member, 309 Posts

For reference, the error it throws is:

Fatal error: Call to undefined method BasicAuth::protect_site_if_necessary() in /var/www/vhosts/ on line 78


1 May 2010 at 9:37pm Forum Moderator, 5511 Posts

Hmm strange you're using 2.4? I can see the protect_site_if_necessary() function in the BasicAuth.php file. You want to check your BasicAuth.php file to check that function is there. It may not have been updated correctly.

Ryan M.

2 May 2010 at 4:13am Community Member, 309 Posts

I'm using 2.3.3


3 May 2010 at 9:19pm Forum Moderator, 5511 Posts

Well even my 2.3 site has this, perhaps if you updated the core before (say it was an earlier version) maybe the BasicAuth file didn't get updated.

The function which should be in BasicAuth.php looks like...

    * Call {@link BasicAuth::requireLogin()} if {@link BasicAuth::protect_entire_site()} has been called.
    * This is a helper function used by Controller.
   static function protect_site_if_necessary() {
      if(self::$entire_site_protected) {
         self::requireLogin("SilverStripe test website. Use your CMS login.", "ADMIN");

You could try (if your missing it) just putting that in the BasicAuth.php file. Also note the 2.3 branch is up to 2.3.7 so your 4 versions behind the latest security updates so if you are worried about it, your site could be compromised.