-1

My script:

<?php
//header("refresh: 7;");
include 'theme.php';
ceklogin();
css();
echo '<script type="text/javascript"
    src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
    $(document).ready(
            function() {
                setInterval(function() {
                    var randomnumber = Math.floor(Math.random() * 100);
                    $("#show").text(
                            "I am getting refreshed every 3 seconds..! Random Number ==> "
                                    + randomnumber);
                }, 3000);
            });
</script>';
exec('/www/openvpn_wget_status.sh');
echo '<br>';
echo file_get_contents( "/www/openvpn_status.txt" );
echo '<div id="show">';
//include 'wget.log';
//echo "<br><textarea name=\"text-info\" id=\"scores\" rows=\"30\" cols=\"90\" readonly style=\"font-family: Arial;font-size: 7pt;\" >";
//$datalines = file ("wget.log");
//foreach ($datalines as $zz) {
//echo $zz; }
echo '</div>';
//echo "</textarea><br></div>";
echo '<script type="text/javascript">
       var textarea = document.getElementById("scores");
       textarea.scrollTop = textarea.scrollHeight;
      </script>';
foot();
echo '

</div>
</body>
</div>
</html>';
?>

it works perfectly but what if I want the variable from a log file in my webserver, let's say the name of the log file is wget.log and I want to refresh it every 3 seconds since wget.log keeps changing as I run wget to download files?

hillz
  • 537
  • 6
  • 10
  • 18

1 Answers1

0

Script to read file (readFile.php)

<?php
//in this script, read any file(or do something else)
//whatever you output, it will be processed in ajax request from below script
echo "<pre>".file_get_contents( "/www/openvpn_status.txt" )."</pre>"; //used <pre> to keep linebreaks in file.
?>

HTML (another file)

<script type="text/javascript"
    src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
    $(document).ready(
            function() {
                setInterval(function() {
                    $("#show").load("readFile.php"); //it will make ajax call to readFile.php and get output from that script and load to #show div
                }, 3000);
            });
</script>

<div id="show">
This will be refreshed every 3 seconds.
</div>
Ravi Dhoriya ツ
  • 4,435
  • 8
  • 37
  • 48