Go Back   Dynamic Drive Forums > General Coding > PHP
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-08-2006, 11:33 PM
InNeedofHelp InNeedofHelp is offline
Regular Coders
 
Join Date: Feb 2006
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page refresh

what's the simplest method of making the page refresh using PHP code?
echo a meta refresh? echo some javascript?
if neither of those is best, what is? and how would one script it?
also if it is the meta refresh, how does one script that?

thanks
Reply With Quote
  #2  
Old 06-08-2006, 11:45 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

javascript is the worst... it is JS dependant and varies by browser. JS can also be turned off, so it's not reliable.

Use meta:
<meta http-equiv="refresh" content="5;url=newpage.php">

Must be in the head section.

Note that the 5 means five seconds... use whatever number of seconds you want, 0 for immediate.
no quote after url, any relative or absolute url will work.

Yeah, echo that: echo "...here...";

The best method is to send an http header with php. That will be even better than meta. Not sure about that code, though.
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #3  
Old 06-09-2006, 12:38 AM
InNeedofHelp InNeedofHelp is offline
Regular Coders
 
Join Date: Feb 2006
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Allright, great. Thanks.

One more thing -
When the page does reload, are all of the $_POST variables cleared?
For example, i go from a post reply page, to my forums page. My forums page inputs the reply info using the $_Post variables, and then the page refreshes from a meta tag. Are those $_Post variables cleared on refresh?
Reply With Quote
  #4  
Old 06-09-2006, 01:31 AM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

I understand the question, but I'm not quite sure.

Have you noticed that when you are browsing and have just sent a form, then hit refresh, that it says "Warning: the page you are refreshing contains POST data. Refreshing will send it again"; or something.

I believe it depends on the browser.

I'm not sure if it only refreshes with post data if you do so by hitting the refresh command, rather than, for example, a meta refresh.

However, with a meta refresh, you can specify the same URL as the current page, and it won't resend the data.

<meta http-equiv="refresh" content="0">
Where 0 is the time in seconds. Since the url is omitted, it's just the current page.
That WOULD likely resend the data.
With the example from above:
<meta http-equiv="refresh" content="5;url=newpage.php">
It would just be transferred to newpage.php, whether or not it was the current page, without any post data as the meta refresh is basically equivalent to an automatic link set to be "clicked" at X seconds into the page.

Bottom line-- you can certainly insure that the data WON'T be sent again if you specify the page as a url, rather than just refreshing the current page by omitting the url attribute, but I do not know if you can guarantee that the post data WILL be sent.


*Note: POST may be complex, but GET is very easy. If your forms use the get method, the data will be appended to the end of the URL.
Refreshing or visiting index.php?var=val WILL resend the get data;
refreshing or visiting index.php will NOT resend the get data.
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #5  
Old 06-09-2006, 07:36 AM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

The POST data is never resent.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #6  
Old 06-09-2006, 07:46 AM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

It definitely is if the user clicks refresh, at least in Safari and mozilla... not sure about IE.

Is this disabled, then, from automatic refreshes? Only works if it's user initiated?
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #7  
Old 06-09-2006, 12:18 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Quote:
It definitely is if the user clicks refresh, at least in Safari and mozilla... not sure about IE.
No, the browser detects that the request required POST data and asks if the user wishes to resend it. If you use a meta refresh, the browser will simply navigate to the page to which you point it. There is no way to include POST data in the meta refresh.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #8  
Old 06-09-2006, 07:46 PM
InNeedofHelp InNeedofHelp is offline
Regular Coders
 
Join Date: Feb 2006
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is good news. Thanks Twey and djr.
Reply With Quote
  #9  
Old 06-09-2006, 09:16 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

Ok, that makes sense then.

I know I've asked this before, but I never really got an answer, Twey. Is there any way to send the post data without sending a form?
(I suppose one could code javascript to send a hidden form when a link is clicked... that might work)
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #10  
Old 06-09-2006, 10:11 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

That's actually the simplest and most effective way of doing it. For a bit more flexibility, there's always AJAX, of course.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:44 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.