【发布时间】:2015-12-12 15:30:26
【问题描述】:
好的,所以我有一个计数器,它一次只计数一秒。我希望第二个计数器成为我的会话变量。这是个坏主意吗?此外,当我在第二页上执行 isset 时,它会在我的第二页上显示“您的会话正在运行 0”。我已经确保在我的页面开始时我的 php 会话周围没有多余的白色区域,但我认为这不是问题所在。我也尝试在我的 countUP 函数上应用明确的间隔,但它不起作用?我真的很感谢你的帮助。
第一页.php
<?php session_start();
if(!isset($_SESSION["counter"])){ //checkingto see if a variable called my score exist
$_SESSION["counter"]=0; //if not, initates this variable with 100
}
?>
第一页_javascript
<script type="text/javascript">
var counter=0; //initiates score to 100
var timer_container = document.getElementById("timer_container"); //get div that wil display the score
timer_container.innerHTML="Time = " + counter; //popo
var timer;
function countUP() {
counter = counter +1;//increment the counter by 1
//display the new value in the div
document.getElementById("timer_container").innerHTML = counter;
} </script>
page2.php
<?php session_start();
if(isset($_SESSION['counter'])){
echo "Your session is running ".$_SESSION['counter'];
}
else { echo "Session not running";}
?>
javascript的第2页
<script type="text/javascript">
var counter=<?php echo $_GET['counter'];?>; //initiates score to 100
var timer_container =document.getElementById("timer_container"); //get div that will display the score
timer_container.innerHTML="Time="+counter;
//var timer;
function countUP() {
counter = counter+1; //increment the counter by 1
//display the new value in the div
document.getElementById("timer_container").innerHTML = counter;
} </script>
我之前在另一个游戏中使用过它,它运行良好。谢谢
【问题讨论】:
标签: javascript php