PHP + MySQL을 사용하고 있습니다.PHP 동시 사용자를 사용하는 방법
어쨌든 내 PHP 페이지에 액세스 할 수있는 동시 사용자 (1 명의 사용자 만 1 명의 사용자)를 제어 할 수 있습니까? 다른 컴퓨터에서 내 PHP에 액세스하는 키를 복사 할 수 없으며 PHP 세션/쿠키를 통해이를 처리하는 방법은 무엇입니까?
조언을 보내 주시면 감사하겠습니다.
PHP + MySQL을 사용하고 있습니다.PHP 동시 사용자를 사용하는 방법
어쨌든 내 PHP 페이지에 액세스 할 수있는 동시 사용자 (1 명의 사용자 만 1 명의 사용자)를 제어 할 수 있습니까? 다른 컴퓨터에서 내 PHP에 액세스하는 키를 복사 할 수 없으며 PHP 세션/쿠키를 통해이를 처리하는 방법은 무엇입니까?
조언을 보내 주시면 감사하겠습니다.
물론 가능합니다. 세션 테이블을 만들고 사용자가 로그인을 시도 할 때 로그인 한 사용자를 확인하십시오. 해당 사용자에 대해 등록 된 세션이 있으면 로그인을 모두 거부합니다.
Keepalive 시간을 설정할 때 세션 정리 만 기억해야합니다.
이 솔루션을 사용해 볼 수 있습니다.
concurrent_users.php
// created cookie with createdSessionID
$cookie_array = explode("-", $_COOKIE['cookie']); //retrieve contents of cookie in an array
//print("cookie:" . $cookie_array[0]); //display the content
//Retrieve data from TBL_LogUsersCurrent
$QueryI = "SELECT * FROM TBL_LogUsersCurrent WHERE UserID=".$_SESSION['SessionUserID']."";
$ResultI = mysql_query($QueryI);
//fetch the query result
$Row = mysql_fetch_array($ResultI,MYSQL_NUM);
$Arr_Row = $Row[4];
//echo "database:" .$Arr_Row;
//compare the createdSessionID in cookie and database
if ($cookie_array[0] != $Arr_Row) {
//redirect the user to login page if already the user has logged in
header ("Location: http://" . $_SERVER['HTTP_HOST'] . "/". $SystemFolder . "/index.html?AS=1$extraA");
mysql_close();
//Deleting Cookies:Expiration date should be in the past, to trigger the removal mechanism in the browser.
setcookie("cookie", $_SESSION['createdSessionID'],time() - 3600);
exit();
}