php PHP杀戮开关

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php PHP杀戮开关相关的知识,希望对你有一定的参考价值。


https://github.com/AndrewChamp/website-killswitch

1) In the clients server, create a killswitch class: killswitch.php

<?php
	class killswitch{
	 // Update 'killswitch.php' w/ the URL of where your 'killswitch.xml' file will reside
	 // for example: http://juancadima.com/killswitch.xml
		public $info;
		private $domain;
		private $xml = 'http://domain.com/killswitch.xml';
		
		
		public function __construct($_domain=null){
			if($_domain != null):
				$this->domain = $_domain;
				$this->loadFile();
			endif;
		}
		
		
		public function loadFile(){
			try{
				$xml = simplexml_load_file($this->xml);
				$this->info = $xml->{$this->domain};
			} catch(Exception $e){
				print $e->getMessage();
			}
		}
	
	}
?>


2) This goes in our server: killswitch.xml

status: true   -- site will load fine
status: false  -- client is gonna get a message

<?xml version="1.0" encoding="UTF-8"?>
<domains>
	<site1.com>
		<status>true</status>
		<message>Please contact me immediately.</message>
	</site1.com>
	<!--  Add more sites by adding them to your killswitch.xml file  -->
	<another-site.com>
		<status>false</status>
		<message>Please contact me immediately.</message>
	</another-site.com>
</domains>




============= Add this at the top of your client's index file  ==========

<?php
require_once "killswitch.php";  // from step (1)

$check = new killswitch($_SERVER['HTTP_HOST']);
if($check->info->status == 'false')
	exit($check->info->message);

// ... rest of the app continues if status was true





以上是关于php PHP杀戮开关的主要内容,如果未能解决你的问题,请参考以下文章

PHP PHP国家代码到大陆与开关

JQuery 开关滞后于开关所基于的变量一键(从 PHP 文件中检索时)

php根据html切换开关显示数据库中的数据

PHP-开关包括

PHP日期开关

php wp-config开关