Search code examples
phpincludehref

Included file changing url


I have searched the internet for a couple of hours now but i cant find the answer to my question.

How can i switch between url with included php file?

My include file is the following:

<li class="werkgeversNavbar">
    <a href=<?php echo '"'.'http://'.$_SERVER['SERVER_NAME'].'/dritjob/werkgevers.php"'?>>Voor werkgevers </a>
    <a href=<?php echo '"'.'http://'.$_SERVER['SERVER_NAME'].'/dritjob/index.php"'?>>Voor werkzoekende </a>
</li>

For instance when i am on my 'index.php' i want the first link to be shown, and when i click on that link i want the 'werkgevers.php' to change into 'index.php'.

How can this be achieved? Sorry for my bad english any replay would be great, thank you for your time!


Solution

  • This is just a quick fix for your problem, but you can do more complicated if you've get the point:

    <li class="werkgeversNavbar">
        <?php
        if ($_SERVER['SCRIPT_NAME'] == '/index.php') {
            ?>
            <a href="http://<?php echo $_SERVER['SERVER_NAME'];?>/dritjob/werkgevers.php">">Voor werkgevers </a>
            <?php
        } else {
            ?>
            <a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/dritjob/index.php">Voor werk zoekende </a>
            <?php
        }
        ?>
    </li>