(on Friday, 22 October 2010, 05:12 PM +0200):
> Well from user/edit i am redirected to user/login
>
> In the login action i do:
>
> $origin = $this->request()->getHeader('referer');
> var_dump($origin);
>
> And it gives me:
>
> index/index
>
> But i expect
>
> user/edit
Ooops, my bad; you need to store the page that sent you to the login
form:
// on login page:
$referer = $this->getRequest()->getHeader('referer');
// don't forget to sanitize the referer and ensure it goes to a page
// on your site!
$session = new Zend_Session_Namespace('login');
$session->referer = $referer;
Then, after successful login:
$session = new Zend_Session_Namespace('login');
$referer = $session->referer;
if (empty($referer)) {
$referer = /* some default page */;
}
return $this->_redirect($referer);
> On Fri, Oct 22, 2010 at 4:58 PM, Matthew Weier O'Phinney
> <matthew@zend.com>wrote:
>
> > -- 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.
> >
> > --
> > 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
> >
>
>
>
> --
> Met vriendelijke groet,
>
> Jigal Sanders
> A.J. Ernststraat 739
> 1082 LK Amsterdam
> Mobiel: 06-42111489
--
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
没有评论:
发表评论