Capture url 2 clicks back

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Problem is that it goes from form to link to link ..


Cheers
Last edited by bob_the _builder on Fri Sep 01, 2006 1:37 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why not form to form to link, where the second form is a button?
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

$referer post across in a form to the following code:

Code: Select all

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 ... 
                 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; 
                }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>'; 
}
after the form its uses a link to confirm deletion, after the confirmation link is used the valuse $_POST['referer'] is now invalid.

So I thought the answer maybe grab the post value and make it a variable in the delete link and grab the $_GET variable here:

<meta http-equiv="refresh" content="3; url='.$_GET['referer'].'">';

Is sending the post value containing a web address across the url a acceptable way to go?

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So I was thinking...

page1.php (includes a delete button for an image - this is the page you want to come back to):

Code: Select all

<?php
$this_page = basename(__FILE__);
?>
<form method="post" action="page2.php">
<input type="hidden" name="referer" value="<?php echo $this_page; ?>" />
<!-- Other HTML form field -->
</form>
page2.php (This is the confirm page)

Code: Select all

<?php
$referer = $_POST['referer'];
/* Handle the rest of the form processing here */
/* and present the user with a choice */
?>
<form method="post" action="page3.php">
<input type="hidden" name="referer" value="<?php echo $referer; ?>" />
<input type="hidden" name="delete_id" value="<?php echo $id_passed_through_php; ?>" />
<!-- Other HTML form field for confirmation -->
</form>
page3.php (This page actually processes and redirects)

Code: Select all

<?php
$referer = $_POST['referer'];
/* Handle all actual processing */
/* Then either header() redirect OR */
/* Meta redirect in the HTML output */
/* Using the $referer var as your ultimate location */
?>
Post Reply