1

i have al little code and i need to reload a block of the code every 10 seconds. Is that possible?

Code:

<?php
session_start();
$site_host = "hollander-ict.nl";
$sql_port = 3306;
$web_port = 80;

if (!fsockopen($site_host,$sql_port)) {
echo "SQLi machine error: Unreachable SQL server. Try again!";
}
if (!fsockopen($site_host,$web_port)) {
echo "SQLi machine error: Unreachable web server. Try again!";
}
?>
Koen Hollander
  • 1,687
  • 6
  • 27
  • 42

2 Answers2

2

Something very basic to get you started. You might want to add a timeout in your code.

setInterval(function(){
    $.get('file.php', function(data){
        $('#div').html(data);
    });
},10000);
Ben Fortune
  • 31,623
  • 10
  • 79
  • 80
  • Could you add the correct code in my script above? I doesn't have any experience with AJAX – Koen Hollander Nov 21 '13 at 16:06
  • You would use this on another page, with jQuery loaded on your page. It would then send requests to `file.php`, which would be the page with your PHP. – Ben Fortune Nov 21 '13 at 16:08
1

If you want to do this with Ajax, you can use the answer of Ben Fortune.

When you just want the page to be refreshed every 10 seconds, you can also use header()

header( 'refresh: 10; url=url-to-refresh.php' ); 
Benz
  • 2,317
  • 12
  • 19