Page 1 of 1
Problem with links
Posted: Wed Sep 17, 2003 2:25 pm
by gstefan
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.
Posted: Wed Sep 17, 2003 3:47 pm
by m3rajk
best way to get absolute path is to prepend what you have with
Code: Select all
$pathstart=getcwd();.'/';
$pathToFIle=$pathstart.'menu.php';
Posted: Thu Sep 18, 2003 11:56 am
by gstefan
I've just solved this problem:
menu.php:
<?php
print '<a href="/root/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';
?>
Thankx for your answers!
Posted: Thu Sep 18, 2003 2:54 pm
by m3rajk
what happens if you change directories? that's why the getcwd() is handy
Posted: Fri Sep 19, 2003 1:46 am
by gstefan
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
Posted: Fri Sep 19, 2003 1:57 pm
by m3rajk
can we see your full code? this time in [ php] [/ php] around the code (but without the space)?
i think there might be an issue
Posted: Fri Sep 19, 2003 2:29 pm
by jason
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:
Code: Select all
<base href="http://www.example.com/">
And then simply create all your links as if you were linking to them from the index page. It's that simple.
Posted: Sat Sep 20, 2003 4:30 pm
by gstefan
I try with
<base href="http://localhost/...">
and it works.
It's really 100% html only.
Thankx.