Quite simple. Take advantage of the HTTP_REFERER index available at
$_SERVER.
You should take this into consideration and add it to your login form
when the login was accessed without submitting any data. So on your
controller where you handle the login (I assume you use a login()
action) you could do something like:
function login()
{
if (!empty($this->data))
{
$user = $this->User->findByLogin($this->data['User']['login']);
if($user !== false && $user['User']['password'] ==
sha1($this->data['User']['password']))
{
$this->Session->write('User', $user);
if (isset($this->data['User']['url']))
{
$this->redirect($this->data['User']['url']);
}
else
{
$this->redirect('/');
}
}
else
{
$this->set('errorMessage', 'The account you\'ve
specified is not
valid.');
}
}
else if (isset($_SERVER['HTTP_REFERER']))
{
$this->set('url', $_SERVER['HTTP_REFERER']);
}
}
and on your login.thtml view file you would have something like:
<?php if(!empty($errorMessage)): ?>
<p class="error"><?php echo $errorMessage; ?></p>
<?php endif; ?>
<?php echo $html->formTag('/account/login'); ?>
<?php
if (isset($url))
{
$html->hiddenTag('User/url', $url);
}
?>
User: <?php echo $html->input('User/login'); ?><br />
Password: <?php echo $html->password('User/password'); ?><br />
<br />
<?php echo $html->submit('Login'); ?>
</form>
Hope it helps.
-MI
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---