How to use a global variable for a link

1

I'm trying to use $_SERVER['DOCUMENT_ROOT'] to make it easier to use links where I could call the variable in any directory on the site. To use with include($pagina_inicial) works, but for link does not work:

For example:

<?php
$pagina_inicial = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
?>
<a href="<?php $pagina_inicial ?>">Link</a>
// Seria o equivalente disso:
<a href="www.site.com/index.php">Link</a>
// Mas está retornando assim: 
// http://www.site.com/home/u711323471/public_html/index.php

Does anyone know how I can do this?

    
asked by anonymous 04.10.2014 / 07:14

2 answers

2

With I suggested before , it is best to use related paths.

For example, / is root. So you can only do $pagina_inicial = '/index.php'; and in another directory: $pagina_inicial = '/outra_dir/index.php';

Or do not use php variables and do:

<a href="/index.php">Link</a> // se o ficheiro estiver na root
<a href="/../index.php">Link</a> // se o ficheiro estiver numa descendente direta da root
    
05.10.2014 / 09:43
1

You could use HTTP_HOST or SERVER_NAME , I believe they will pass the variable the way you want it.

If you have questions, PHP Manual has a page only for the $_SERVER functions, take a look here .

    
04.10.2014 / 13:19