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
  • 441
  • 5
  • 14

4 Answers4

1

Try this

echo $_SERVER['SERVER_NAME'];
Saty
  • 22,443
  • 7
  • 33
  • 51
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
  • 859
  • 2
  • 12
  • 33
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,864
  • 3
  • 25
  • 33
0
<?php
    echo "Your Website Root : " . $_SERVER['SERVER_NAME'];
?>
Manohar Kumar
  • 605
  • 9
  • 12