0

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.

Geeky Ninja
  • 6,002
  • 8
  • 41
  • 54

2 Answers2

1
 $domain_name = parse_url('http://example.com/');
 if ($_SERVER['SERVER_NAME'] ==  $domain_name['host'])
 {
 // some thing here
  }
Suresh Suthar
  • 794
  • 8
  • 15
-1

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

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
M at
  • 1,020
  • 1
  • 12
  • 26
  • 2
    `mysql_query()` ?? Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 29 '18 at 12:04
  • @RiggsFolly No argue that you are RIGHT. Although as in my defence that's a quote from another website, I do not think we are here to share a prefect code to use in real projects, But we are telling how the question can be solved! (There are always lots of attention point should I write 0 to 100 ? or should I solve the pure problem ?) – M at Mar 31 '18 at 08:05