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.
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:
(php-how-to-get-the-base-domain-url)
$_SERVER['SERVER_NAME'];
Checking if data exist in database
$result = mysql_query('SELECT COUNT(*) FROM
table
WHEREfield
= ...'); 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