I have a php application getting x and y position constantly from the server. Based on the value of x and y, it places an image on screen. The page is constantly refreshed every 10 seconds. I want to save the previously obtained x and y value (before refresh) in to x1 and y1 and then store the currently obtained value in x and y (after refresh), so that I can calculate x1-x and y1-y.
<?php
session_start();
if(isset($_SESSION['x1']))
$_SESSION['x1'] = $x;
else
$_SESSION['x1'] = 0;
$x = //Some method of fetching the x position from server
?>
Problem with the above code is, that during every refresh the value of x1 is replaced with current x, i.e. x1 becomes equal to x. How do I make x1 to retain its value.
The most obvious solution: Put the values into the session at the end of the request.