creating a redirect
Moderator: General Moderators
creating a redirect
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?
with header('Location: '.$redirectURL); a 302 redirect is sent to the client.
Server variables: $_SERVER
Server variables: $_SERVER
you may use this to track the client's origin.'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.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
<?php
// do some stuff
header("Location: $SERVERї'HTTP_REFERER']");
?>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)
assuming your form's method is "POST" tryif uncertain print the passed values withinstead of your original script.
the $_POST array was introduced in php 4.1.
Check your current version with
I doubt that will be sufficient (but it may be)
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)<input type="hidden" name="redirect" value="http//path/to/my/page.php">
assuming your form's method is "POST" try
Code: Select all
// <-- some processing here but no output -->
header('Location: '.$_POSTї'redirect']);Code: Select all
<?php echo '<pre>', print_r($_POST); echo '</pre>';the $_POST array was introduced in php 4.1.
Check your current version with
Code: Select all
<?php phpinfo(); ?>