[英]I want to match the domain name with the Website URL
Suppose, I have an URL like http://www.example.com/page1.html
. 假设我有一个类似http://www.example.com/page1.html
的URL。 In my database I have domain like this http://example.com/
. 在我的数据库中,我拥有类似http://example.com/
域。
Now, if the domain name exists in the DB, I want to return that in the URL. 现在,如果域名存在于数据库中,我想在URL中返回该域名。
$domain_name = parse_url('http://example.com/');
if ($_SERVER['SERVER_NAME'] == $domain_name['host'])
{
// some thing here
}
Spliting your answer into two parts: 将答案分为两部分:
( php-how-to-get-the-base-domain-url ) ( php如何获取基本域URL )
$_SERVER['SERVER_NAME']; $ _SERVER [ 'SERVER_NAME'];
Checking if data exist in database 检查数据库中是否存在数据
$result = mysql_query('SELECT COUNT(*) FROM
table
WHEREfield
= ...'); $ result = mysql_query('SELECT COUNT(*)FROMtable
WHEREfield
= ...'); if (!$result) { die(mysql_error()); 如果(!$ result){die(mysql_error()); } if (mysql_result($result, 0, 0) > 0) { // some data matched } else { // no data matched } } if(mysql_result($ result,0,0)> 0){//一些数据匹配} else {//没有数据匹配}
*. *。 You may need to read more about Database and everything. 您可能需要阅读有关数据库和所有内容的更多信息。 Just look at here 看看这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.