0

I am trying to find the hostname of the sql using wordpress. ie I wanted to print the 'localhost' from 'http://**localhost**/velocity/wordpress/?page_id=4'

I tried the function home_get_url(), but I got the entire path as shown above. When I was trying with gethostname() I got my PC name. '

Please help. I am a fresher to wordpress.

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Vishnu Jayan
  • 149
  • 3
  • 16
  • possible duplicate of [Extract Scheme and Host from HTTP\_REFERER](http://stackoverflow.com/questions/1144856/extract-scheme-and-host-from-http-referer) – hoijui Jun 18 '15 at 05:17
  • check out this question: http://stackoverflow.com/questions/1144856/extract-scheme-and-host-from-http-referer – hoijui Jun 18 '15 at 05:17

2 Answers2

1

Hope it will help you .

printf("MySQL host info: %s\n", mysql_get_host_info());

You can also try .

<?php
echo gethostname(); // may output e.g,: sandie

// Or, an option that also works before PHP 5.3
echo php_uname('n'); // may output e.g,: sandie
?>

For more info . http://www.php.net/manual/en/function.gethostname.php

praveen_programmer
  • 1,072
  • 11
  • 25
  • Just FYI - `mysql_get_host_info()` is [deprecated](http://php.net/manual/en/function.mysql-get-host-info.php) since `php>=7.0.0` use my `mysqli_get_host_info()` ( although I am not sure how to use in in wordpress when the `$link` parameter is needed . Would be interested to know .. – Obmerk Kronen May 20 '18 at 19:45
0

You can use $_SERVER['HTTP_HOST']

For http://localhost/velocity/wordpress/?page_id=4 it will return http://localhost

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87