I have the following problem:
(something like this)
menu.php:
<?php
print '<a href="page2/page2.php">Page2</a>';
?>
index.php: //main page
<?php
include ('menu.php');
print '<br>index';
?>
page2.php
<?php
include ('../menu.php');
print '<br>page2';
?>
page2.php is in a subdirectory and when I use the link from the menu this is like this:
page2/page2/page2.php
How can I use menu.php and the link do the same thing always no matter in what subdirectory I am.
Thanks.
Problem with links
Moderator: General Moderators
best way to get absolute path is to prepend what you have with
Code: Select all
$pathstart=getcwd();.'/';
$pathToFIle=$pathstart.'menu.php';I try with getcwd() as you said. The problem was that when I click on the link the browser ask me if I want to download entirepath\page2\page2.php
I test this on my computer. I have PHPEd from nuSphere and I have also Apache 1.3.27 and use http://localhost/root/site/index.php and the link was http://localhost/root/site/page2/page2.php
I test this on my computer. I have PHPEd from nuSphere and I have also Apache 1.3.27 and use http://localhost/root/site/index.php and the link was http://localhost/root/site/page2/page2.php
This was not a PHP issues. Had nothing (read as 0%) to do with PHP. It is merely the way HTML works.
If your on this page:
http://www.example.com/page2/page2.php
And you click on a link that points to:
page2/page2.php
You go here:
http://www.example.com/page2/page2/page2.php
Now, the most efficient way to solve this problem is not even the way gstefan want's to solve it. Rather, use this:
And then simply create all your links as if you were linking to them from the index page. It's that simple.
If your on this page:
http://www.example.com/page2/page2.php
And you click on a link that points to:
page2/page2.php
You go here:
http://www.example.com/page2/page2/page2.php
Now, the most efficient way to solve this problem is not even the way gstefan want's to solve it. Rather, use this:
Code: Select all
<base href="http://www.example.com/">
Last edited by jason on Sat Sep 20, 2003 5:32 pm, edited 1 time in total.