Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to get root url of my application

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #161117
    sshuvro58
    Participant

    I want to print the root URL of my application folder . like http://localhost/metro/ , here metro is my folder where I am working .

    No matter which directory I am currently in it will print out the http://localhost/metro/

    I have tried this

    <li class=""><a href="<?php $server = $_SERVER['HOST'] .'/metro';echo $server;?>" target="_self" class="">Home</a></li>

    But doesn’t work , Actually I want to build a navigation menu , by which can I always navigate to the place I want , no matter which place I am currently in

    #161126
    __
    Participant

    I have tried this

    <li class=""><a href="<?php $server = $_SERVER['HOST'] .'/metro';echo $server;?>" target="_self" class="">Home</a></li>

    That would work, except for the fact that $_SERVER["HOST"] —unless you created it yourself— doesn’t exist. I would suspect you’re thinking of $_SERVER["HTTP_HOST"]?

    A better solution might be to define a constant: for example, if the above gives you the correct value:

    define( "MY_ROOT_URL",$_SERVER["HTTP_HOST"]."/metro" );
    

    then,

    <a href="<?= MY_ROOT_URL ?>">Home</a>
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.