2017-06-15 99 views
-6

鎖定功能,我需要知道如何去實現這個想法在PHPPHP OOP如何從同一個用戶

Add random sleep (max 30s) after validation, if it was successful to emulate some long running process. 
Do not allow to make bet for the same user until response is not returned to `Bet.php` calling class. 

If player tries to pass more than one request and his previuos is not finished yet, return appropriate 
`error_code` from the list provided. 

我認爲,在我存儲所有玩家不能讓打賭我能創建列表,賭注我認爲這是不好的和可選的。

也許我可以添加一些列的數據庫表「用戶」,如果玩家用或不

+0

你不需要爲此的數據庫。只是使用一個PHP會話(隱式cookie) – Phil

+2

太多的問題沒有接受;這裏的記錄不是很好 –

回答

1

使用PHP-Session。開始會話以使用cookie跟蹤用戶,以便您可以決定用戶是否第一次訪問該網站。然後保存開始時間。

<?php 
session_start(); // start session to get access to $_SESSION and set an individual cookie for each user 

if(!isset($_SESSION['time'])) 
{ 
    $_SESSION['time'] = time(); 
    // start the timer 
} 
else 
{ 
    $difference = round(abs($_SESSION['time'] - time())/60,2); 

    if($difference < 30) 
    { 
     die('Your need to wait!'); 
    } 

    echo "The time is over."; 
}