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

  • Home
  • SEARCH
  • 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 500383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:04:54+00:00 2026-05-13T06:04:54+00:00

I have some Zend Framework apps running and it’s time to add user access

  • 0

I have some Zend Framework apps running and it’s time to add user access restrictions. I am a firm believer that you should try to avoid rolling your own security infrastructure whenever possible and so I have been trying to figure out how to use Zend_Auth and Zend_Acl to implement it, so far without success.

I have searched all over the net, and at least one book, and I can’t find an example of how to string all of the parts together. I found an example of authentication here, old examples of authorization / access control here and here, and proposals for the future here, here, and here, but I don’t understand ZF well enough to put it all together in the present.

What I need is this: a simple public example or tutorial that completely details [as downloadable and runnable code] how to use the current Zend Framework release (1.9.5, no “proposals” or “laboratories”) to manage the authentication/authorization/access control of three users (and their passwords) in three different roles (e.g. guest, member, administrator) to protect three different controllers in the default module. The example should use as much of the current ZF library as possible. And no, this isn’t homework; the stakes are higher than that 🙁

If it exists somewhere I haven’t found it. Any help appreciated. IMO this would be very helpful for newcomers to ZF.

Disclosure: I have a community wiki question on ZF here beause I’m trying to figure out if I’ll continue with it. But I really need to get my apps running now!

  • 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-13T06:04:54+00:00Added an answer on May 13, 2026 at 6:04 am

    Pro Zend Framework Techniques, Chapter 8 has a nice treatment of this. Most of his approach is quite similar to what I use, with the exception of the preDispatch method. When authenticating I have preDispatch redirect instead of silently dispatching to another controller. I also preserve the Url that was requested for the use of the login action.

    class SitePluginAuth extends Zend_Controller_Plugin_Abstract
    {
     private $_auth;
     private $_acl;
    
     private $_noauthPath = '/account/log-in/';
     private $_noacl = array('module' => 'default', 'controller' => 'error', 'action' => 'denied');
    
     public function __construct($auth, $acl)
     {
      $this->_auth = $auth;
      $this->_acl = $acl;
     }
    
     public function preDispatch($request)
     {
      $resource = $request->controller;
      if (!$this->_acl->has($resource)) return;
    
      $controller = $request->controller;
      $action = $request->action;
      $module = $request->module;
    
      if ($this->_auth->hasIdentity()) {
       $identity = $this->_auth->getIdentity();
       $role = 'member';
      }
      else {
       $role = 'guest';
      }
    
      /*
       * Remember to URL encode the parameter value. Also, when you are processing the value of the 
       * redirect URL, make sure that it is a URL on your site or a relative URL to avoid any security 
       * attacks like a phishing scheme. Otherwise, a third party can target your site's login page and 
       * then redirect back to their site and might have access to the user's secured session.
       *
       * The reason I don't use the session to store the URL, is that search engine spiders can end up 
       * creating sessions as they hit links on your site that are secured and require login. Since they 
       * have no credentials, the session is created only to timeout 30 minutes later.
       */
      if (!$this->_acl->isAllowed($role, $resource, $action)) {
       if (!$this->_auth->hasIdentity()) {
        $requestedUrl = substr($request->getRequestUri(), strlen($request->getBaseUrl())); // relative url 
        $loginUrl = $this->_noauthPath.'?requestedUrl='.urlencode($requestedUrl);
        $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
        $redirector->gotoUrl($loginUrl);
       }
       else {
        $request->setModuleName($this->_noacl['module']);
        $request->setControllerName($this->_noacl['controller']);
        $request->setActionName($this->_noacl['action']);
       }
      }
     }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are some of the ways you have implemented models in the Zend Framework?
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
We have some files on our website that users of our software can download.
I have a script that appends some rows to a table. One of the
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to

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.