Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to redirect to the previous page?

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I am looking for a way that when a user submits a form they are sent to a page saying "processing..." or something like that and then are sent back to the page they were just at.

I tried sending along the previous page's URL with PHP_SELF like so:

<input type=&quot;hidden&quot; name=&quot;formHttpReferer&quot; value=&quot;<?php echo &quot;$PHP_SELF&quot;; ?>&quot; />

Then on the page I have a redirect with the variable &formHttpReferer as the URL:

header(&quot;Refresh: 3; URL=$formHttpReferer&quot;);

This refreshes the page, but remains on the current processing page rather than going back to whence it came. Could anyone help out??
 
u can use $HTTP_REFERER global variable of PHP.
in this case u dont need to send anything as a hidden value.

spookie --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I thought I had heard less and less browsers are supporting this variable, because of privacy issues. Has anyone else heard this?
 
yes thats true..some old browsers dont support this predefined variable and if ur behind firewall it can give u a empty string(i am not too sure abt this..).

if the twoi pages(the form page and the page that says processing) are different, why dont u pass the filename as hidden variable to the second page and then redirect using that variable..
ie.
<input type=&quot;hidden&quot; name=&quot;formHttpReferer&quot; value=&quot;
spookie


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I don't often like to use javascript, but in this case, you're really interested in the client-side history... I suppose you might do something with sessions, but far easier would be to use:

<a href=&quot;javascript:history.go(-1)&quot;>go back a page</a>

I haven't tried inserting that into a header... perhaps it's doable...
 
I developed a system that keeps track of the last page you were on that was different to the page you're now on, both with ?arguments=1 and without arguements. These 2 pages demonstrate it =) I've hardly used it myself, heh, as normally back operations know where they're supposed to be going anyway and you can specify it. I also found $php_self (or is it $phpself) doesn't work for me, either it's my config or the config on my webserver but I don't use it I use $_SERVER['PHP_SELF'] instead.

page 1
-----------------------------
Code:
<?
	if ($prev_self != $_SERVER['PHP_SELF']) {
		$old_self = $prev_self;
		$prev_self = $_SERVER['PHP_SELF'];
	}
	if ($prev_request != $_SERVER['REQUEST_URI']) {
		$old_request = $prev_request;
		$prev_request = $_SERVER['REQUEST_URI'];
	}
	$rand1 = rand(1,10);
	$rand2 = rand(1,10);
	echo &quot;<font color=red>Current Self = &quot;.strtolower($_SERVER['PHP_SELF']).&quot;</font><br>&quot;;
	echo &quot;<font color=red>Current Request = &quot;.strtolower($_SERVER['REQUEST_URI']).&quot;</font><br>&quot;;
	echo &quot;<font color=green>Prev self = $prev_self</font><br>&quot;;
	echo &quot;<font color=green>Old self = $old_self</font><br>&quot;;
	echo &quot;<font color=blue>Prev request = $prev_request</font><br>&quot;;
	echo &quot;<font color=blue>Old request = $old_request</font><br>&quot;;
?>
<form action=&quot;fromtest.php?<?= $rand1 ?>,<?= $rand2 ?>&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_self&quot; value=&quot;<?= $prev_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_self&quot; value=&quot;<?= $old_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_request&quot; value=&quot;<?= $prev_request ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_request&quot; value=&quot;<?= $old_request ?>&quot;>
<input type=submit value=test1.php>
</form>
<form action=&quot;fromtest2.php?<?= $rand1 ?>,<?= $rand2 ?>&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_self&quot; value=&quot;<?= $prev_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_self&quot; value=&quot;<?= $old_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_request&quot; value=&quot;<?= $prev_request ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_request&quot; value=&quot;<?= $old_request ?>&quot;>
<input type=submit value=test2.php>
</form>

page 2
-----------------------------
Code:
<?
	if ($prev_self != $_SERVER['PHP_SELF']) {
		$old_self = $prev_self;
		$prev_self = $_SERVER['PHP_SELF'];
	}
	if ($prev_request != $_SERVER['REQUEST_URI']) {
		$old_request = $prev_request;
		$prev_request = $_SERVER['REQUEST_URI'];
	}
	$rand1 = rand(1,10);
	$rand2 = rand(1,10);
	echo &quot;<font color=red>Current Self = &quot;.strtolower($_SERVER['PHP_SELF']).&quot;</font><br>&quot;;
	echo &quot;<font color=red>Current Request = &quot;.strtolower($_SERVER['REQUEST_URI']).&quot;</font><br>&quot;;
	echo &quot;<font color=green>Prev self = $prev_self</font><br>&quot;;
	echo &quot;<font color=green>Old self = $old_self</font><br>&quot;;
	echo &quot;<font color=blue>Prev request = $prev_request</font><br>&quot;;
	echo &quot;<font color=blue>Old request = $old_request</font><br>&quot;;
?>
<form action=&quot;fromtest.php?<?= $rand1 ?>,<?= $rand2 ?>&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_self&quot; value=&quot;<?= $prev_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_self&quot; value=&quot;<?= $old_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_request&quot; value=&quot;<?= $prev_request ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_request&quot; value=&quot;<?= $old_request ?>&quot;>
<input type=submit value=test1.php>
</form>
<form action=&quot;fromtest2.php?<?= $rand1 ?>,<?= $rand2 ?>&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_self&quot; value=&quot;<?= $prev_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_self&quot; value=&quot;<?= $old_self ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;prev_request&quot; value=&quot;<?= $prev_request ?>&quot;>
<input type=&quot;hidden&quot; name=&quot;old_request&quot; value=&quot;<?= $old_request ?>&quot;>
<input type=submit value=test2.php>
</form>
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Cool, thanks for all the feedback guys. Yeah, I did start just using a hiddent form value of &quot;formHttpReferer&quot; for the value of the page before. I couldn't get PHP_SELF to work either, but I just cleaned the string to get the filename, since they are all located in the same directory anyways :)

It works now for the most part. Leozack- I'll definately look into your technique. Thanks a lot, man. All you guys- thanks!

Dust
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top