Ruben
Ruben

Reputation: 489

PHP get base link current site

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.

Upvotes: 0

Views: 138

Answers (4)

Manohar Kumar
Manohar Kumar

Reputation: 613

<?php
    echo "Your Website Root : " . $_SERVER['SERVER_NAME'];
?>

Upvotes: 0

Sourabh Kumar Sharma
Sourabh Kumar Sharma

Reputation: 2807

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>

Upvotes: 0

Yogesh Pawar
Yogesh Pawar

Reputation: 334

Try this

echo $_SERVER['SERVER_NAME'];

Upvotes: 1

Nicholas Mordecai
Nicholas Mordecai

Reputation: 879

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.

Upvotes: 0

Related Questions