0

I have a php-project which is uploaded to a website, my index.php is located at the root of my project which is made like this: http://www.website.com/projectroot . Is there any way to get the link of my projectroot in php from any subdirectory or phpscript? If http://website.com would be my project root, it should return website.com.

Ruben
  • 379
  • 4
  • 12

4 Answers4

1

Try this

echo $_SERVER['SERVER_NAME'];
Saty
  • 22,213
  • 7
  • 30
  • 49
Yogesh Pawar
  • 336
  • 2
  • 17
0

I'm not entirley sure what you're asking for, but most people use

$_SERVER["DOCUMENT_ROOT"]

If this isn't what you're after, then you may be better off creating a subdomain or vhost in your httpd file.

Nicholas Mordecai
  • 739
  • 2
  • 9
  • 31
0

You can use the global variable in php: $_SERVER['SERVER_NAME'].
Example how you can use that:
<a href = "<?php echo $_SERVER['SERVER_NAME']; ?>"> Link to Main Site</a>

Sourabh Kumar Sharma
  • 2,804
  • 3
  • 21
  • 32
0
<?php
    echo "Your Website Root : " . $_SERVER['SERVER_NAME'];
?>
Manohar Kumar
  • 475
  • 7
  • 12