Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2008, 01:55 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default HTTP Referers

Hello all,

First of all, I'm just getting started with the Zend Framework. I do like it a lot. I've run into a conundrum concerning logging in and referers. I'm trying to figure out the best way to explain it.

I've got three controllers: Index, Auth, Update. Right now, if you try to go to any Update action without being logged in (via Zend_Auth), preDispatch() sending you to auth/login. That bit works fine. The problem is, I can't figure out a clean way of remembering whether you came to auth/login from update/add, update/edit, or update/delete. $_SERVER['HTTP_REFERER'] is only being set as the Index controller, not the update/{action} I'm going for. I hope that makes sense.

Does anyone know of anything inside ZF that I can use to keep track of the referring action? Or know of a better way of doing this?

Thanks,

-mike

Last edited by july4th : 02-22-2008 at 02:07 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-22-2008, 05:53 AM
Member
 
Join Date: Jun 2007
Posts: 33
Default

I have login available anywhere on my site, and to get people back to their original page after a successful login I simply use $this->_redirect($_SERVER['HTTP_REFERER']);

I haven't had any problems with it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-22-2008, 11:22 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

HTTP_REFERER is not working since you are sending users to the login form, which i'm guessing is located at /index, as opposed to embedded in all pages such as jhorra suggests.

This should work fine in your case:
if (is_null($this->auth) || !$this->auth->hasIdentity())
{
$session = new Zend_Session_Namespace('<insert a suitable namespace>');
$session->destination = $_SERVER['REQUEST_URI'];
$this->_redirect('<insert login page>'); // since you are using a plugin this call will have to be modified. But you've already grasped that part.
}

Now when you've authenticated the user simply redirect them to $session->destination.
Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-22-2008, 11:40 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default

Leif:

The login is a separate controller but I do that same check for auth->hasIdentity(). The problem I was running into is the action I was selecting in the Update controller was never being set as the HTTP_REFERER, probably because I never reached that action as the script never got past preDispatch(). I'll give the sessions a try but I was hoping there'd be something built into the framework to help.

-Either that, or forgo the preDispatch() and check for auth->hasIdentity() in every action. Hmm.- Edit: Nope, didn't work. HTTP_REFERER is still being set as the index.

Thanks for your reply.

Last edited by july4th : 02-22-2008 at 11:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-22-2008, 05:03 PM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default

Quote:
Originally Posted by Leif.Högberg View Post
HTTP_REFERER is not working since you are sending users to the login form, which i'm guessing is located at /index, as opposed to embedded in all pages such as jhorra suggests.

This should work fine in your case:
if (is_null($this->auth) || !$this->auth->hasIdentity())
{
$session = new Zend_Session_Namespace('<insert a suitable namespace>');
$session->destination = $_SERVER['REQUEST_URI'];
$this->_redirect('<insert login page>'); // since you are using a plugin this call will have to be modified. But you've already grasped that part.
}

Now when you've authenticated the user simply redirect them to $session->destination.
Hope this helps.

Worked like a charm. Thanks Leif.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:24 PM.