简体   繁体   中英

I want to match the domain name with the Website URL

Suppose, I have an URL like http://www.example.com/page1.html . In my database I have domain like this http://example.com/ .

Now, if the domain name exists in the DB, I want to return that in the URL.

 $domain_name = parse_url('http://example.com/');
 if ($_SERVER['SERVER_NAME'] ==  $domain_name['host'])
 {
 // some thing here
  }

Spliting your answer into two parts:

  1. ( php-how-to-get-the-base-domain-url )

    $_SERVER['SERVER_NAME'];

  2. Checking if data exist in database

    $result = mysql_query('SELECT COUNT(*) FROM table WHERE field = ...'); if (!$result) { die(mysql_error()); } if (mysql_result($result, 0, 0) > 0) { // some data matched } else { // no data matched }

    *. You may need to read more about Database and everything. Just look at here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM