-1

I am really new in php. Here is my code:

$domain = $_SERVER['HTTP_HOST'];
$uri = parse_url($_SERVER['HTTP_HOST']);
$r_domain = substr(['host'], strpos($uri['host'],"."), strlen($uri['host']));

if ( $domain == $r_domain ) {

/*Open the connection to our database use the info from the config file.*/
$link = f_sqlConnect('root', '', 'group_project');
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1) `substr(['host'],...` is a typo; 2) if you parse `$_SERVER['HTTP_HOST']` you obtain only `$uri['path']` – fusion3k Apr 01 '16 at 18:08

1 Answers1

1

parse_url is intended to parse a string in this form:

scheme://host/path?query#fragment

So, if you parse this string:

https://www.example.com/pages/mypage.php?one=two#wow

the result of parse_url will be:

Array
(
    [scheme] => https
    [host] => www.example.com
    [path] => /pages/mypage.php
    [query] => one=two
    [fragment] => wow
)

But you parse $_SERVER['HTTP_HOST'], that is something like ‘localhost’, ‘www.mysite.com’, ‘127.0.0.1’. In other words, a string without a particular significance for parse_url, because there is not any element to associate it with an URL.

Parsing (i.e.) ‘localhost’ will obtain only this:

Array
(
    [path] => localhost
)
fusion3k
  • 11,568
  • 4
  • 25
  • 47