Sunday, 8 July 2018

Show same content at same time in different browser

I am developing a numbers game where users will buy numbers and after 2 days winners will be drawn.

I am using PHP for the backend and jQuery for the frontend.

My problem is when drawing occurred user on different browser can't see same numbers, these draw numbers are being generated by PHP.

I was thinking maybe I can build these game by PHP and Javascript but it looks not easy. Can you guys please suggest some alternative? How can I improve this code to show the same number on the different browser?

I have the idea that it is not possible to generate a random number for each request. Maybe I can save the number in the database and then get this number in PHP such that the number will be unique for each request.

The actual issue is to create the same content for each user in different browsers. Any help would be really appreciated.

Javascript:

var myTimer = setInterval(checkDrawDate, 1000);

function checkDrawDate() {
      var today = new Date();
      var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
      var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
      var dateTime = date+' '+time;
      var x = new Date(dateTime);
      var y = new Date(""); //this is laravel variable which contain drawdate e.g. 2017-07-05

      if(x >= y){
          drawNumber();
    }
}

function drawNumber(){
      $.get("",{'gameId': gameid}, function(res){
       $('#mybets').html(res.html); 
     });
}

PHP:

public function ajaxDrawNumber(Request $req){
     return rand(0,49);
}



from Show same content at same time in different browser

No comments:

Post a Comment