Redirect and THEN Refresh
Moderator: General Moderators
Redirect and THEN Refresh
Hello,
javascript:history.back()
?
A simple command to take you back to the page that you came from, a history minus 1 command.
You can use it as a hyperlink or a timeout script etc..
I use this command in a PHP update page. The update is made to the database and then after 'x' seconds the user is redirected, back to where he came from.
BUT, when I get back to the original page I have to hit REFRESH to see the new updates.
Is there any way of modifying the code:
javascript:history.back()
so that it Refreshes the page it goes back to?
Cheers,
Bes.
javascript:history.back()
?
A simple command to take you back to the page that you came from, a history minus 1 command.
You can use it as a hyperlink or a timeout script etc..
I use this command in a PHP update page. The update is made to the database and then after 'x' seconds the user is redirected, back to where he came from.
BUT, when I get back to the original page I have to hit REFRESH to see the new updates.
Is there any way of modifying the code:
javascript:history.back()
so that it Refreshes the page it goes back to?
Cheers,
Bes.
No.
Use PHP to find the Referrer and then use
BTW - this is the General Discussion forum, not a help forum.
Use PHP to find the Referrer and then use
Code: Select all
header("location: ???.htm");Grim...
(don't use this forum much and not sure where to post.)
How do I use PHP to find the referrer?
The only thing that is parsed to my update.php file is the variable that came from the orignal .php file.
?value={$row['newvalue']}
parsed to update.php, and then: -
Update WHERE ID=$newvalue
The value in $newvalue is updated to the server.
B U T , this value could be from one of numerous files!
I don't know how to define where that value came from and how to refer to it.
More help please?
Bes.
(don't use this forum much and not sure where to post.)
How do I use PHP to find the referrer?
The only thing that is parsed to my update.php file is the variable that came from the orignal .php file.
?value={$row['newvalue']}
parsed to update.php, and then: -
Update WHERE ID=$newvalue
The value in $newvalue is updated to the server.
B U T , this value could be from one of numerous files!
I don't know how to define where that value came from and how to refer to it.
More help please?
Bes.
It doesn't take long to find out.besbajah wrote:Grim...
(don't use this forum much and not sure where to post.)
In answer to your question...
Code: Select all
$ref=@$HTTP_REFERER; //referring URL
header ("location: ".$ref);
exit;- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
its actually possible and I've also given this snippet before to a member here...
what amazes many is that reload bit still executes after the page location has changed 
Code: Select all
<script>
history.back();
location.reload();
</script>OK, thanks Grim...I'm getting my head around it.
..but the code that currently sends the user back to the original page is part of a java script and at the end of an IF statement: -
else
{
javascript:history.back()
}
and I've no idea how to modify that to point to PHP code.
AND I'VE JUST SEEN n00b Saibot's response as I write.
BRILLIANT, I think that's exactly what I need. I'm off for a quick play. Get back to you soon.
Bes.
..but the code that currently sends the user back to the original page is part of a java script and at the end of an IF statement: -
else
{
javascript:history.back()
}
and I've no idea how to modify that to point to PHP code.
AND I'VE JUST SEEN n00b Saibot's response as I write.
Code: Select all
<script>
history.back();
location.reload();
</script>Bes.
OK, it works fine,
but, and it's a big but, the code is VERY dangerous because it can go into an endless loop until the redirect page is found. I click my update page and it works fine, updating the database once, but then it can suddenly go dippy and refer me to a page 3 or 4 histories back. The update may be repeated 3 or 4 times on the database too, and that's very dangerous.
I need something more stable, what do you think?
Bes.
but, and it's a big but, the code is VERY dangerous because it can go into an endless loop until the redirect page is found. I click my update page and it works fine, updating the database once, but then it can suddenly go dippy and refer me to a page 3 or 4 histories back. The update may be repeated 3 or 4 times on the database too, and that's very dangerous.
I need something more stable, what do you think?
Bes.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
Whatbesbajah wrote:OK, it works fine,
but, and it's a big but, the code is VERY dangerous because it can go into an endless loop until the redirect page is found. I click my update page and it works fine, updating the database once, but then it can suddenly go dippy and refer me to a page 3 or 4 histories back. The update may be repeated 3 or 4 times on the database too, and that's very dangerous.
No, it doesn't go into an endless loop, just repeats 3, 4 or 5 times, redirecting me to a history point 3, 4 or 5 steps back. Very odd because if I take the
out of the script it works fine, except no Refresh of course!
Code: Select all
location.reload();Try not to double post. Pressing the "Submit" button _once_ does the job just fine.besbajah wrote:No, it doesn't go into an endless loop, just repeats 3, 4 or 5 times, redirecting me to a history point 3, 4 or 5 steps back. Very odd because if I take the
out of the script it works fine, except no Refresh of course!Code: Select all
location.reload();
As regards your problem, try this:
Code: Select all
window.location = window.location;