I have included "header.php" on my pages to fix redundancy.
In header.php you'll find the navigation, style sheets and scripts.
The problem is, I cannot use header.php dynamically on different pages because it has a static links.

Pls help me. im a newbie here. Thanks in advanced!

Recommended Answers

All 5 Replies

Member Avatar

im a newbie here

What with 70 posts?!

How about some code? It'll help enormously if you post your relevant code.

What with 70 posts?!

Ok, this is not my account. My brother lend me his account for me to skip registration and have a fast answer in my problem.

To explain further...

<link rel="/css/style.css">
<script src=/js/jscript.js"></script>

        <li><a href="menu1.php">menu1</a>
                <li><a href="menu/submenu1.php">submenu1</a>               
                <li><a href="menu/submenu2.php">submenu2</a>
        <li><a href="menu2.php">menu2</a>

So image those codes inside header.php, and header.php is being called in every page of a website.
The problem is if these link were static, if you are in other directory, you will surely have a bad link. you will not get the path you want.

How do I make it dynamic?

Member Avatar

I'd advise people to have all their 'public' files in one directory. In fact I'd route all files through index.php and use .htaccess to rewrite. However, if you can't do this. Use the file as it is because you've got absolute referencing due to the '/' at the beginning of the url. This means it doesn't matter from where you are calling it in the directory.

Im interested in that .htaccess rewriting solution. Can you show me how will you do it? Thank you!

Member Avatar

Im interested in that .htaccess rewriting solution.

Have you googled? Try 'htaccess mod rewrite'

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/*([^/]*)/*([^/]*)/*([^/]*)/*([^/]*)/*$ index.php?lang=$1&top=$2&middle=$3&bottom=$4&sub=$5 [L]

That's an example file.
If turns look at this:


and reads it as


You just use the $_GET variables to load the right include file

into the index file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.