Page 1 of 1
creating a redirect
Posted: Sat Nov 23, 2002 2:23 pm
by rathlon
I have a simple update form for my database where users view the current info that is loaded and then update whatever they want via an html form. If the user updates info I have it go to a results page showing what was changed. How do I redirect the user back to the page where he or she was before, using php?
Posted: Sat Nov 23, 2002 5:26 pm
by volka
with
header('Location: '.$redirectURL); a
302 redirect is sent to the client.
Server variables: $_SERVER'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
you may use this to track the client's origin.
Posted: Sat Nov 23, 2002 5:41 pm
by rathlon
since I'm not too abreast of the multiple facets in the php language, I'll assume that your speaking of using sessions here?
Posted: Sat Nov 23, 2002 8:21 pm
by volka
not necessarily. e.g. you may also ship the url as hidden field within a form

Posted: Sun Nov 24, 2002 12:16 am
by rathlon
yeahhhhhhhhhhhhhhhhhhhhhhhhhh...............well, I must be totally retarted b/c I tried that whole
<input type="hidden" name="redirect" value="http//path/to/my/page.php">
and ahhhhhhhhh......well...no go.
?
Posted: Sun Nov 24, 2002 12:17 am
by hob_goblin
Code: Select all
<?php
// do some stuff
header("Location: $SERVERї'HTTP_REFERER']");
?>
try that
Posted: Sun Nov 24, 2002 12:50 am
by volka
that will lead directly to the page that generated the form (except the parse error because of the inner literal

)
I doubt that will be sufficient (but it may be)
<input type="hidden" name="redirect" value="http//path/to/my/page.php">
if you're not including the server such as
http://my.server/path/to/my/page.php skip the leading
http. The processing script must not output any content other than header information (also see:
Sticky: Before Post Read: Warning: Cannot add header information)
assuming your form's method is "POST" try
Code: Select all
// <-- some processing here but no output -->
header('Location: '.$_POSTї'redirect']);
if uncertain print the passed values with
Code: Select all
<?php echo '<pre>', print_r($_POST); echo '</pre>';
instead of your original script.
the
$_POST array was introduced in php 4.1.
Check your current version with