所有现场刷新[关闭]

When I click a button I want the site to refresh for all users online so that then an audio plays.

Would I need to use PHP for this or?

<div id="button"></div>

 $(window).load(function(){
var audio = new Audio('audio_file.mp3');
audio.play();
});

$("#button").click(function(){
window.location.reload();
});

you don't need PHP and actually you can't do it Easily in php . Php is a server side language means it can do things on your server and just present it to the client or take back data from the Client. what you want to do is a Client side operation.

UPDATE :: i miss understood it . so you need to create a Php file on your side , say call it Admin.php

what Admin.php will do is creating a database values with the audio file location and name and if it's ready to be played or not .

<?php
$dbh=new PDO('mysql:dbname=DB;host=localhost;charset=utf8','user','pass'); 
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}
$insert = $dbh->prepare ("Insert INTO Audio (Audioval,location) VALUES (:Audioval,:location)");
$insert->bindParam(': Audioval',"1"); // 1 play audio , 0 no audio
$insert->bindParam(': location',"x.mp3");
 $insrt->execute();
?>

and another one let's call it Users.php , it will check if there's an Audio file to be played from the database .

<?php
$dbh=new PDO('mysql:dbname=DB;host=localhost;charset=utf8','user','pass'); 
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}
$stmt = $dbh->prepare ("SELECT * FROM Audio");
while ($results = $stmt->fetch()) {
$Audio=$results['Audioval'];$location =$results['location'];
}
if ($Audio==1){
echo "<script>var audio = new Audio('".$location."'); audio.play();</script>";
}

?>

and the Client side script that will keep checking for Users.php

 setInterval(function, 60000); // this will call it every mint
function checkaudio (){
      $.ajax({
        type: "POST",
        url: "Users.php",
        data: "",
        success: function(T)
        { 
        $("#Audio").html(T).show(); 
    }
        });
}