Home > Article > Backend Development > PHP code to check if local server
This article introduces a piece of PHP code used to detect whether it is a local server. It is very simple and can be used as a reference for beginners.
Check whether it is a local server and take next steps. code show as below: <?php /** * 检测服务器属性 * edit bbs.it-home.org */ function is_localhost() { $localhost_ids = array('localhost', '127.0.0.1'); if(in_array($_SERVER['HTTP_HOST'],$localhost_ids)){ // not valid return 1; } } ?> Code description: Obtain the server information through $_SERVER['HTTP_HOST'], and then match the setting value of the database to know whether it is a local server. |