How can I detect if the user is on localhost in PHP?

前端 未结 9 1258
耶瑟儿~
耶瑟儿~ 2020-12-12 12:45

In other words, how can I tell if the person using my web application is on the server it resides on? If I remember correctly, PHPMyAdmin does something like this for securi

9条回答
  •  囚心锁ツ
    2020-12-12 13:37

    I found a easy answer.

    Because all local drives have C: or D: or F: ... etc.

    Just detect if the second character is a :

    if ( substr_compare(getcwd(),":",1,1) == 0)
    {
    echo '';
        $client_or_server = 'client';
    }
    else
    {
    echo '';
        $client_or_server = 'server';
    }
    

提交回复
热议问题