Capture url 2 clicks back
Moderator: General Moderators
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
Capture url 2 clicks back
Hi,
How can I capture and store a url (not in db) from 1-2 clicks previous then use header location to direct back to that page?
$HTTP_REFERER; can only go back 1 page?
Thanks
How can I capture and store a url (not in db) from 1-2 clicks previous then use header location to direct back to that page?
$HTTP_REFERER; can only go back 1 page?
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Not a very clean example but it should give you something to think on.
So to go back two pages....
Code: Select all
<?php
session_start();
function stack_page()
{
$_SESSION['page_trail'][] = $_SERVER['PHP_SELF'];
}
function get_prev_page($back=1)
{
$trail = $_SESSION['page_trail'];
if (isset($trail[count($trail)-1-$back]))
{
return $trail[count($trail)-1-$back];
}
else return false;
}
?>Code: Select all
if ($old_page = get_prev_page(2))
{
header('Location: '.$old_page);
}- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
REQUEST_URI not better?Code: Select all
$_SESSION['page_trail'][] = $_SERVER['PHP_SELF'];
What about using javascript:
Code: Select all
history.go(-2);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Javascript is not the best way, especially if the page was processed through a form post (as this will take you back to the then-current state of the page).
If this is your progression:
record_list -> edit_form -> edit_ok
Then you can pass the record_list page name to the edit form as a hidden field, then when the form is submitted, the record_list page name gets sent along with it to edit_ok, where you can redirect back to it from there.
If this is your progression:
record_list -> edit_form -> edit_ok
Then you can pass the record_list page name to the edit form as a hidden field, then when the form is submitted, the record_list page name gets sent along with it to edit_ok, where you can redirect back to it from there.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
Hi,
Basically its a photo gallery, there are options to delete gallerys, sub gallerys and images, they have a delete link above each, also with pagination.
If they choose to delete a photo it sends them to a page with the form and delete button, upon hitting the delete button it takes them to a process page that processs the delete function. 2 steps (pages)
1st page has all the forms for the functions and the 2nd page has all the functions to process the forms.
When its complete I want to use something like:
Not sure of the best way to go?
Thanks
Basically its a photo gallery, there are options to delete gallerys, sub gallerys and images, they have a delete link above each, also with pagination.
If they choose to delete a photo it sends them to a page with the form and delete button, upon hitting the delete button it takes them to a process page that processs the delete function. 2 steps (pages)
1st page has all the forms for the functions and the 2nd page has all the functions to process the forms.
When its complete I want to use something like:
Code: Select all
header("Refresh: 3; url=index.php?action=the_page _they _came_from");Thanks
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Have you given my 'theory' a try? Seems like it would be most useful for a situation like yours (in fact, I know it would be, I have used it for the exact same situation as you).bob_the _builder wrote:Hi,
Basically its a photo gallery, there are options to delete gallerys, sub gallerys and images, they have a delete link above each, also with pagination.
If they choose to delete a photo it sends them to a page with the form and delete button, upon hitting the delete button it takes them to a process page that processs the delete function. 2 steps (pages)
1st page has all the forms for the functions and the 2nd page has all the functions to process the forms.
When its complete I want to use something like:
Not sure of the best way to go?Code: Select all
header("Refresh: 3; url=index.php?action=the_page _they _came_from");
Thanks
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
Hi,
I used Everah idea posting a hidden field:
and feyd meta option:
Thanks.
I used Everah idea posting a hidden field:
Code: Select all
<input name="referer" type="hidden" value="'.$_SERVER["HTTP_REFERER"].'">Code: Select all
<meta http-equiv="refresh" content="3; url='.$_POST['referer'].'">Thanks.
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
Hi,
Actually the hidden field option didnt work very well now, as I added code to confirm deletion, Basically now $_Post['referer'] is non existant.
example:
Would it be bad practice to post referer in the delete link and use $_GET to grab it after deletion has happened?
Is there a work around for this, would be nice to keep it simple as it would be without the deletion prompt in there.
The other option is to use the folowing code to confirm deletion:
Is that fail safe across browsers?
Thanks
Actually the hidden field option didnt work very well now, as I added code to confirm deletion, Basically now $_Post['referer'] is non existant.
example:
Code: Select all
case 'delete_subcat':
if (array_key_exists("confirm",$_REQUEST)) {
//Delete code here
echo '<br />Sub category & images were successfully deleted<br /><br /><br />Please wait while you are redirected ...
<meta http-equiv="refresh" content="3; url='.$_POST['referer'].'">';
}else{
echo 'Do you really want to delete this sub category and all its images?';
echo '<br /><br /><a href="index.php?action=process&process=delete_subcat&subcat_id='.$_GET['subcat_id'].'&confirm=y">Yes</a> - <a href="#" onClick="history.go(-1)">No</a>';
}
break;Is there a work around for this, would be nice to keep it simple as it would be without the deletion prompt in there.
The other option is to use the folowing code to confirm deletion:
Code: Select all
<input type="submit" value="Delete Category" onclick="return confirm(\'Are you sure you want to do delete this category?\')">Thanks
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA