Home > Backend Development > PHP Tutorial > mysql - 问一个关于PHP的问题。数组调用数据库。

mysql - 问一个关于PHP的问题。数组调用数据库。

WBOY
Release: 2016-06-06 20:30:44
Original
1094 people have browsed it

这是我在网上找的域名授权程序,现在我不想把授权的域名放在程序本地了,而是放在我自己的Mysql数据库中,请问如何修改呢?

<code>function allow_doamin(){  
$is_allow=false;  
$url=trim($_SERVER['SERVER_NAME']);  
$arr_allow_domain=array("localhost");//这里可以添加多个授权域名  
foreach($arr_allow_domain as $value){  
$value=trim($value);  
$tmparr=explode($value,$url);  
if(count($tmparr)>1){  
$is_allow=true;  
break;  
}  
}  
 if(!$is_allow){  
die('Domain name is not authorized!');  
 }  
}  
allow_doamin();  
</code>
Copy after login
Copy after login

回复内容:

这是我在网上找的域名授权程序,现在我不想把授权的域名放在程序本地了,而是放在我自己的Mysql数据库中,请问如何修改呢?

<code>function allow_doamin(){  
$is_allow=false;  
$url=trim($_SERVER['SERVER_NAME']);  
$arr_allow_domain=array("localhost");//这里可以添加多个授权域名  
foreach($arr_allow_domain as $value){  
$value=trim($value);  
$tmparr=explode($value,$url);  
if(count($tmparr)>1){  
$is_allow=true;  
break;  
}  
}  
 if(!$is_allow){  
die('Domain name is not authorized!');  
 }  
}  
allow_doamin();  
</code>
Copy after login
Copy after login

首先创建一个allow_domain_table

CREATE TABLE test.allow_domain_table (
id INT NOT NULL AUTO_INCREMENT,
host VARCHAR(255) NOT NULL COMMENT '允许的host',
PRIMARY KEY (id));

插入测试数据
INSERT INTO domain_table (host) VALUES ('localhost');
INSERT INTO allow_domain_table (host) VALUES ('127.127.127.127');

$arr_allow_domain=array("localhost");//这里可以添加多个授权域名

这个地方改成查询allow_domain_table表里的数据即可

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template