php navigation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

php navigation

Post by bawla »

im using this code for navigation, but it does not work, i when i click on a link with a code like <a href="?id=news.php" target="main">home</a> it just takes loads my whole site including the layout and everything inside the iframes

Code: Select all

<?php
if ($_GET[page] !=""){
$file = "" . $_GET[page] . ".php";
} else {
$file = "error.php";
}
include("$file");
?>
well first of all, how do i get it for it to look in the directory that the file with this code is in, i tried $file="", $file="/', $file=".", $file="./"

*note - im using iframes as well with this, could that be causing the problem?*

second how would i get it to look into 2 or more directorys for files, for example to look in the one that the file with the code is in and a directory called, downloads

Thanks in Advance :)
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post by Slippy »

You should be careful with that code -- it would be easy to inject code using that structure.

I would recommend using a static navigation if at all possible and then just include that at the top of each page... if you must do it this way because you have your reasons (we all have our reasons) then...

You should use the file_exists() function to do the checking. You could do several checks with various directories and a flag easily enough.

Also, you should clarify if you are using inline frames (iframes) or just frames. Sounds like you want normal html frames.
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

*note - im using iframes as well with this, could that be causing the problem?* - does that clarify it? if it doesnt i dont get wut you mean then
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

why does it not work with iframes?, i tried a different php code and it doesnt work with iframes
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post by Slippy »

Iframes work like standard frames except that you can simply embed them within a normal HTML page without having the parent call the child...

The following snippet of code will load an html page with another page inside it (yahoo)... when you click the link it switches to msn.

Code: Select all

<iframe
name="test"
width="600"
height="400"
src="http://www.yahoo.com"
frameborder="3"
scrolling="yes" >
</iframe><br>
<br>
<a href="http://www.msn.com" target="test">Change to MSN</a>
PHP will add extra functionality to HTML; not take away from it... I would recommend using a STATIC navigation. This means that you have hard links to the various pages on your site and then you can simply put that navigation in your html... you shouldn't need php for this...

What you are trying to write looks like something that would be necessary if the pages were always changing and you weren't sure if the pages were there... is that the case? Can you post the entire code for the page and explain what you want it to do?
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

i know wut iframes are, wut i need is to know why the php code does now work with iframes,
im just trying to use a php code so i can link pages like ?id=something instead of the full name directory/something.php
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post by Slippy »

Sounds like a lot of work for nothing to me...

How about creating an array with all of your links in it and then the user passes in an ID via tha ?id=xxx link and you look up the xxx in the array which will then set the link?

At the same time you could use PHP to create the array of links by recursing through the dir's and compling a list of links that are available...

...may I ask what the purpose is?
Post Reply