Ok, so I have a counter which simply counts up a second at a time.This second counter I want it to be my session variable.Is this a bad idea? Also when I do a isset on my second page its says on my second page "Your session is running 0". I have ensured there are no extra white places around my php session at the start of my page but i dont think thats the problem. I ahve also tried applying clear interval on my countUP function but it doesnt work? Im really thankful for any help.
page one.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
}
?>
page one_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";}
?>
page2 of javascript
<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>
I have used this before in another game and it works perfect. thanks