1
良い一日良い人。私はphp、mysql、javascript、ajaxを使ってカウントダウンタイマーに取り組んでいます。タイマーは動作していますが、ページがリフレッシュされると再起動します。どこが間違っていたのか分かりません。カウントダウンタイマーがページのリフレッシュを行うようにする。
私のタイマー機能:
public function timer(){
$this->getServer();
$t = 45;
$duration = "";
try{
$connection = new PDO("mysql:host=$this->serverName;dbname=$this->serverDatabase",$this->serverUsername,$this->serverPassword);
$time = $connection->prepare("SELECT * FROM duration WHERE duration='$t'");
$time->execute();
if($time->rowCount()>=1){
while($rows = $time->fetch(PDO::FETCH_ASSOC)){
$duration = $rows["duration"];
}
}
$_SESSION["duration"] = $duration;
$_SESSION["start_time"] = date("Y-m-d H:i:s");
$end_time = date('Y-m-d H:i:s', strtotime('+'.$_SESSION["duration"].'minutes', strtotime($_SESSION["start_time"])));
$_SESSION["end_time"] = $end_time;
}
catch(PDOException $e){
die($e->getMessage());
}
}
test.php
session_start();
require_once("connections.php");
require_once("secure.php");
$timer = new main();
$timer->setServer($serverName,$serverDatabase,$serverUsername,$serverPassword);
$timer->getServer();
$timer->timer();
?>
<div id="response"></div>
<script type="text/javascript">
setInterval(function()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "response.php", false);
xmlhttp.send(null);
document.getElementById("response").innerHTML=xmlhttp.responseText;
},1000);
</script>
response.php
<?php
session_start();
$from_time1=date("Y-m-d H:i:s");
$to_time1= $_SESSION["end_time"];
$timeFirst=strtotime($from_time1);
$timeSecond=strtotime($to_time1);
$differenceInSeconds = $timeSecond-$timeFirst;
echo gmdate("H:i:s",$differenceInSeconds);
?>
誰かが私が私が間違って
それが機能しない – healer
セッション変数をもう一度書き込んでいないのですか? – Difster
はい、確信しています – healer