2010年10月22日星期五

Re: [fw-mvc] Referer

-- Matthew Weier O'Phinney <matthew@zend.com> wrote
(on Friday, 22 October 2010, 10:58 AM -0400):
> -- Jigal sanders <jigalroecha@gmail.com> wrote
> (on Friday, 22 October 2010, 04:48 PM +0200):
> > This is more of an architectual question which should lead for me to a
> > development decision.
> > I sometimes in my application have some links. But in order to see what's
> > behind the links you have to be logged in. So the user is redirected to a
> > login page.
> > But I want the user to be redirected to the original page after he has
> > logged in.
> >
> > What's the best way to implement this in a zf based site?
>
> Grab the referer from the request object:
>
> // In an action method of a controller
> $request = $this->getRequest();
> if (/* some op succeeded */) {
> $origin = $request->getHeader('referer');
> return $this->_redirect($origin);
> }
>
> That's really all there is to it.

One thing: somebody asked me to point out that you shouldn't blindly
trust the Referer header, which is an excellent point to make. Run it
through a regexp, and ensure it's actually heading back to *your* site.
:)

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: