Home  >  Article  >  Backend Development  >  PHP code to check if local server

PHP code to check if local server

WBOY
WBOYOriginal
2016-07-25 08:58:321181browse
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.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn