views:

1147

answers:

2

Hi everyone,

I am using a simple Zend_Auth setup to authenticate users for one of my applications, using a check in the preDispatch() method in a controller plugin. When anonymous users navigate to

/users/view/id/6

for example, they should be redirected to the above URI after authentication.

What is the best way to do this? I'd prefer not to store $_SERVER['REQUEST_URI'] in the session. Personally, I'd find storing the entire Zend Request object to cleanest solution, but I am not sure if this is sensible and if this is the approach I should be taking.

Any thoughts?

A: 

We had the same problem and actually did store request URI in session variable. If you don't put any specific, unserializable object into Zend Request, I think it also will be ok to persist it.

However it depends on what throughput you're expecting. Serializing objects like Zend Request may not be the best idea if you have a high traffic website.

xelurg
+1  A: 

Well redirecting or forwarding to the LoginController might not be the optimal way to bring an un-authenticated user to the login page. Instead at preDispatch you can grab the $request object and alter it by doing the following.

$request->setActionName('someaction');
$request->setControllerName('somecontroller');

At this point your original request in maintained yet the page is displaying the login page. Then you can alter your login controller to check to see if the current request location is the login controller or if it something else. If it is something else (the original request) on a successful login send them to that page.

danielrsmith