Mar 19, 2017 Setelah membaca tutorial tentang Cara Membuat Form pada PHP kali ini kita akan membahas tentang Jenis Input Type pada Pembuatan Form PHP.Input type yang sebelumnya sudah pernah ditampilkan hanya ada text dan submit, untuk kesempatan kali ini kita akan membahas lebih detail tentang input type ini, berikut macam, contoh dan penjelasannya.Untuk file kita akan. Cara Membuat Form Entry Data, Edit/Update, Hapus Di PHP; Fungsi Tanggal dan Waktu (Date/Time) pada PHP; Tutorial Array PHP Lengkap dengan Contoh dan Pembahasan; CodeIgniter PHP: (Buku Tutorial CodeIgniter PHP Bahasa Indonesia) ( SMS GATEWAY PHP MYSQL ) Tahap Demi Tahap Membangun SMS Gateway Dengan PHP MYSQL; Cara Membuat Database dengan Xampp.
How can I refresh a page using PHP periodically? If I can not do it by PHP, what is the best recommended scenario?
Aan
AanAan4,3582727 gold badges7070 silver badges135135 bronze badges
13 Answers
You can do it with PHP:
It refreshes your current page, and if you need to redirect it to another page, use following:
Peter Mortensen14.2k1919 gold badges8888 silver badges114114 bronze badges
user1847051
In PHP you can use:
Or just use JavaScript's
Peter Mortensenwindow.location.reload()
.14.2k1919 gold badges8888 silver badges114114 bronze badges
AboQutieshAboQutiesh1,43122 gold badges77 silver badges1414 bronze badges
You sure can refresh a page periodically using PHP:
This will refresh the page every three seconds.
Peter Mortensen14.2k1919 gold badges8888 silver badges114114 bronze badges
1311311,12811 gold badge1010 silver badges2626 bronze badges
Soner Gönül82.5k2727 gold badges155155 silver badges289289 bronze badges
KamleshKamlesh
Build in the
if
statement from. If refresh is needed, echo:See Meta refresh.
EDIT
As pointed out by @warren, the above code will refresh the page immediately. You can set the time with the
MathlightMathlightcontent
vall3,3811010 gold badges5050 silver badges9494 bronze badges
i've found 2 Ways to refresh a PHP content :
1.Using HTML META :
2.Using PHP REFRESH RATE :
ThanosThanos
You cannot do it in PHP. Once the page is loaded, PHP dies and is out of control.
You have a few options:
- Use JavaScript
- Use the refresh meta tag,
<meta http-equiv='refresh'>
I think that the refresh meta tag is the easiest and most convenient.
Peter Mortensen14.2k1919 gold badges8888 silver badges114114 bronze badges
JvdBergJvdBerg17k77 gold badges2828 silver badges5252 bronze badges
echo meta tag like this:URL is the one where the page should be redirected to after refresh.
Pang7,1011616 gold badges6868 silver badges107107 bronze badges
Prakash PatilPrakash Patil
Black Mamba3,49622 gold badges2727 silver badges4848 bronze badges
Siddharth ShuklaSiddharth Shukla
header('Location: .');
seems to refresh the page in Chrome, Firefox, Edge and IE 11.64911 gold badge99 silver badges2424 bronze badges
You can refresh using JavaScript. Rather than the complete page refresh, you can give the contents to be refreshed in a div. Then by using JavaScript you can refresh that particular div only, and it works faster than the complete page refresh.
Peter Mortensen14.2k1919 gold badges8888 silver badges114114 bronze badges
AnoopAnoop
PHP is server-side language, so you can not refresh the page with PHP, but JavaScript is the best option to refresh the page:
Visit Location reload() Method.
PatriksPatriks82011 gold badge77 silver badges2525 bronze badges
One trick is to add a random number to the end of the URL, that way you don't have to rename the file every time. E.g.:
The browser will not cache it as long as the random number is different, but the web server will ignore it.
0x450x45
protected by Bhargav Rao♦Oct 30 '16 at 17:06
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged phprefresh or ask your own question.
I have a very simple chat system I've built using PHP and MySQL (this is my second day ever using these languages) and I am wondering if there is any way to auto refresh the table data I'm pulling from my database and loading into an html table via PHP without having something like Javascript go and reload the whole web page... just reloading the html table with the data in it that PHP filled it up with.... Does that make sense?
Here is my code if it helps (for /chat.php)
Brian Tompsett - 汤莱恩4,3821414 gold badges4040 silver badges107107 bronze badges
Albert RenshawAlbert Renshaw9,5541313 gold badges7272 silver badges157157 bronze badges
2 Answers
The technique is called AJAX and one of the easiest libraries to add to the project would be jQuery. I assume your issue isn't with JavaScript, but with the idea of reloading the entire page.
UPDATEBecause I'm such a nice guy ;) This should work, more or less, I haven't tried it out, so there might be a typo or two:
As for coding techniques, you might want to look into SQL-injections and maybe writing cleaner HTML, but I'm sure you'll get there :)
zrvanzrvan5,22811 gold badge1717 silver badges2323 bronze badges
the only way you would do it without javascript is to use an iframe for the chat interface, and a meta refresh.
but why not use javascript?
Kae VerensKae Verens3,39322 gold badges1717 silver badges3333 bronze badges