开发者

How to use PHP control concurrent users

开发者 https://www.devze.com 2022-12-12 10:20 出处:网络
I am using PHP + MySQL. Is there anyway I can control concurrent user (1 user with only 1 key) to a开发者_运维知识库ccess

I am using PHP + MySQL.

Is there anyway I can control concurrent user (1 user with only 1 key) to a开发者_运维知识库ccess my php page? Not allow copy the key to access from different machine into my php, how to handle this through my php sessions/cookies?

Any advise would be appreciated!


You can try using this solution.

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();
            }


Sure you can. Create a sessiontable and perform a check on logged in users when a user attempts to login. When there is a registered session for that user allready deny the login.

The only thing you must keep in mind is session cleanups when you set a keepalive time.

0

精彩评论

暂无评论...
验证码 换一张
取 消