0

I'm trying to make a simple php page using includes and I'm finding it hard to navigate the urls using ../ to locate the right path to the folder.

Is there an easy way to construct a simple php navigation. Only doing it locally without using mysql and etc.

<a class="list-group-item" href="index.php">Overview &nbsp;<i class="fa fa-tachometer fa-fw"></i></a>
<a class="list-group-item" href="ticket/tickets.php">Tickets &nbsp;<i class="fa fa-ticket fa-fw"></i></a>


<? php 
    $indexURL = ('project/*');
?>
<div id="sidebar" class="sample">
    <div class="search">
        <input type="search" placeholder="Search..."> <i class="fa fa-search fa-2x"></i>
    </div>
    <div class="list-group">
        <a class="list-group-item" href="<?php echo '$indexURL' ?>/index.php">Overview &nbsp;<i class="fa fa-tachometer fa-fw"></i></a>
MrNew
  • 1,384
  • 4
  • 21
  • 43
  • Use absolute urls: `/ticket/tickets.php`, etc. or use a variable that defines the root and you can prefix to each url. – jeroen Jun 22 '15 at 18:23
  • How can I use variable to define the root? that's what I've been trying to find :( – MrNew Jun 22 '15 at 18:24
  • Refer to this for getting the document root. http://stackoverflow.com/questions/15211231/server-document-root-path-in-php – Moonblaze Jun 22 '15 at 18:26
  • can you give me an example how to do it inside href :( php $indexURL = ('project/*'); ?> – MrNew Jun 22 '15 at 18:33
  • @joroen I tried using absolute urls but when im in the ticket.php page then go back to index.php the url is stuck in /tickets/index.php. Index.php is outside /ticket/ – MrNew Jun 22 '15 at 18:42

2 Answers2

0

This line will write out $indexURL, literally. If you want the value of $indexURL, remove the single quotes.

<?php echo '$indexURL' ?>
user2182349
  • 9,569
  • 3
  • 29
  • 41
0

To get absolute path to your document root use:

$_SERVER['DOCUMENT_ROOT'];

This should return c:\wamp\www Or /opt/www Or your location to apache document root. To test this simply type:

echo $_SERVER['DOCUMENT_ROOT'];

To get the folder location use

echo basename(__DIR__); 

will return the current directory name only

echo basename(__FILE__); 

will return the current file name only

echo basename(dirname(__FILE__));

Will return the location of the php file that is running the code. Lets take 3 files for example

home.php
test/pics.php
test/images/editor.php

in your pics.php you need to use functions in editor.php, so you use

Pics.php:

require_once dirname(__FILE__) . '/images/editor.php';

Home.php

require_once 'test/pics.php';