Redirect and THEN Refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Redirect and THEN Refresh

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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.
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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;
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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)
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post 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.
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :?:
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post 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!
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
Post Reply