Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:08:54+00:00 2026-05-25T10:08:54+00:00

I am building a site that requires a simple authentication system to sit on

  • 0

I am building a site that requires a simple authentication system to sit on top of my site so that only people with the password can access it. This is different to users and the authentication component as it’s just to prevent access unless you’re supposed to.

The reason is I have a preview site for a client and I only want them to be able to access it but can’t use the in-built authentication as they need to see both logged in and logged out states hence using a custom simple authentication (note this doesn’t need to be secure).

I have a working system in place and to prevent access I do a check in the AppController so that all requests first check if my session exists:

public function beforeRender()
{
    if ($this->Session->check('client') != true)
    {
        $this->layout = 'client_login'; 
        $this->render = 'pages/client_login';
    }
}

The layout bit works fine so it understands the session, but it doesn’t show my client login view which has a simple login form on it so it’s not doing the render properly. Any ideas why not? And any better ideas to show the layout and view for all actions across the site if that session does not exist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:08:55+00:00Added an answer on May 25, 2026 at 10:08 am

    ‘render’ is a function, not a property. So your code should probably be:

    $this->render('pages/client_login');
    

    edit: by the way, this code can’t be placed in the beforeRender() callback, because this would lead to an infinite loop (render() raises beforeRender()).

    beforeFilter() would certainly be a better place.

    function beforeFilter()
    {
        if ($this->Session->check('client') != true)
        {
            $this->autoRender = false;
            $this->layout = 'client_login';
            $this->render('/pages/client_login');
        }
    }
    

    EDIT

    Like explained in my comments, the explicit call to render() in the PagesController->display() method prevents what you want to do to work when you are on an URL that uses the PagesController.

    Rethinking a bit about your needs, I see two solutions.

    If you need a simple way to fully protect your website temporarely, without modifying your application code, you could use Apache to protect the access through the .htaccess. A basic authentication or maybe a filter on IP or domain could maybe do the trick in your case. See http://httpd.apache.org/docs/2.0/howto/auth.html

    If you want to use Cake because you already have your custom authentication system working that fill the Session, you could use the Auth component just to grant or deny access. In your AppController, you could have something like:

    function beforeFilter()
    {
        $this->Auth->loginAction = '/pages/client_login';
    
        if($this->Session->check('client'))
        {
            $this->Auth->allow('*');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a basic CodeIgniter site that requires a login before you can access
I am building a site that uses a simple AJAX Servlet to talk JMS
I'm building a site that's sort of a cross between StackOverflow and Digg (only
I'm building a very simple ASP.NET MVC site that doesn't require a database and
I'm building a site in Zend that requires the ability to upload a list
I'm wondering if there's a best practice for this, I'm building a site that's
I'm building a site that requires multiple forms for the same model in varying
I am building a site that is permissions based. The user can add or
I'm building a site that requires an audio file to be played with an
I am building a site that will (obvisouly) have a front end public portion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.