Page 1 of 1

Redirect and THEN Refresh

Posted: Thu Nov 24, 2005 7:58 am
by besbajah
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.

Posted: Thu Nov 24, 2005 8:14 am
by Grim...
No.

Use PHP to find the Referrer and then use

Code: Select all

header("location: ???.htm");
BTW - this is the General Discussion forum, not a help forum.

Posted: Thu Nov 24, 2005 8:30 am
by besbajah
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.

Posted: Thu Nov 24, 2005 8:41 am
by Grim...
besbajah wrote:Grim...
(don't use this forum much and not sure where to post.)
It doesn't take long to find out.

In answer to your question...

Code: Select all

$ref=@$HTTP_REFERER; //referring URL
header ("location: ".$ref);
exit;

Posted: Thu Nov 24, 2005 8:52 am
by n00b Saibot
its actually possible and I've also given this snippet before to a member here...

Code: Select all

<script>
history.back();
location.reload();
</script>
what amazes many is that reload bit still executes after the page location has changed 8)

Posted: Thu Nov 24, 2005 9:04 am
by besbajah
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.

Code: Select all

<script> 
history.back(); 
location.reload(); 
</script>
BRILLIANT, I think that's exactly what I need. I'm off for a quick play. Get back to you soon.
Bes.

Posted: Thu Nov 24, 2005 9:23 am
by besbajah
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.

Posted: Thu Nov 24, 2005 9:29 am
by n00b Saibot
besbajah 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.
What 8O it shouldn't go into endless loop :? because javascript has executed only once, why should it go into loop... does your code have header redirects in them :?:

Posted: Thu Nov 24, 2005 2:50 pm
by besbajah
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

Code: Select all

location.reload();
out of the script it works fine, except no Refresh of course!

Posted: Thu Nov 24, 2005 3:13 pm
by foobar
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

Code: Select all

location.reload();
out of the script it works fine, except no Refresh of course!
Try not to double post. Pressing the "Submit" button _once_ does the job just fine. :wink:

As regards your problem, try this:

Code: Select all

window.location = window.location;
That'll most likely do a "real" reload, not just a refresh from the cache. That's probably what's going wrong with your page, it's getting the cached content mixed up.