Home > Net >  How do I get my site domain and hosting using php?
How do I get my site domain and hosting using php?

Time:12-26

This way I link to my files in html and php. Because by rewriting the url, the styles change and the face of the site becomes ugly. But this method is not very good because it does not work on some sites.
Sample of my code:

<?php $domain = example.com ; $host = $_SERVER['HTTP-HOST'];?>

<link rel="stylesheet" href="<?php echo "http://$host/$domain" ?>style.css" >

CodePudding user response:

May be come must be like this?

<?php
$domain = 'example.com';
$host = $_SERVER['HTTP_HOST'];
if ($host === 'localhost') {
    $host .= "/$domain";
}
?>

<link rel="stylesheet" href="<?php echo "http://$host/" ?>style.css" >

UPD: Added dynamin host naming for localhost host.

  • Related