redirecting back
Moderator: General Moderators
redirecting back
I am trying to redirect back to the previous page whatever it may be. Is that possible?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Well, when the user deletes an entry from the database, he/she gets the 'The record has been deleted from the database.' message. After that message I want to put a link that redirects the user to the page where he/she comes from. The problem is that there are multiple pages that this delete thing can be done, so I don't know where to redirect the page. I just have to redirect it 'back'.Ambush Commander wrote:Yeah.
(I'm sure you meant to ask How?)
(Well, be more specific. What exactly is this "previous page"?)
I found that there is a variable called $_SERVER['HTTP_REFERER'] that returns the URL of the referring page as a string but I couldn't use it. I get an undefined index:'HTTP_REFERER' error everytime I use it.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Code: Select all
<a href="javascript:history.go(-1)">back to previous page</a>Hey thanks that worked! It seems I really have to learn jspatrikG wrote:Code: Select all
<a href="javascript:history.go(-1)">back to previous page</a>
On your form page...
and the delete page use the following link.
Code: Select all
<form action="deletepage.php" method="post">
PUT FORM HERE
<input name="currentpage" type="hidden" value="<? echo $_SERVER['PHP_SELF'];?>">
<input name="Submit" type="submit">
</form>Code: Select all
<a href="<? echo $_POST['currentpage']; ?>">Go back to previous page</a>Read http://blog.phpdoc.info/archives/13-XSS-Woes.html why this code is open for an XSS attack.jwalsh wrote:Code: Select all
<input name="currentpage" type="hidden" value="<? echo $_SERVER['PHP_SELF'];?>">
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
hi timv, do you think the SERVER variable HTTP_REFERER can be of any use?
I do not see this code working.'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.
Code: Select all
<?php
if(isset($_SERVER['HTTP_REFERER'])){
echo $_SERVER['HTTP_REFERER'];
}else
echo "I dont know the previous page";
?>change to...I do not see this code working.
Code: Select all
<?php if(isset($_SERVER['HTTP_REFERER'])){ echo $_SERVER['HTTP_REFERER']; }else echo "I dont know the previous page"; ?>
Code: Select all
<?php
if(isset($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'];
}else {
echo "I dont know the previous page";
}
?>That doesn't really work either, because a UserAgent is not required to send that header.. Therefor, it's not certain that it will exist.. As the OP already mentionned..
The advantage of a script/task stack as i suggested is that it also allows you to control users that hit the back button.. Or generate breadcrumbs.. Or keep the user at the same page untill he completes the required actions..
The advantage of a script/task stack as i suggested is that it also allows you to control users that hit the back button.. Or generate breadcrumbs.. Or keep the user at the same page untill he completes the required actions..