k now the menu shows up but the only thing that won’t show up are my news.php and when I click on my test page when my main menu comes up it doesnt show up either. What can the problem be?
Indentation can performs miracles for readability.
<?
$val = $_GET'nfn'];
$val .= ".php";
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val);
if (isset($_GET'nfn'])) {
if (file_exists($val)) {
include "$val";
}
else {
include "index.php";
}
}
else {
include "news.php";
}
?>
news.php, if present in the same directory as the file that contains the code you posted will be shown if there is no “?nfs=” or “&nfs=” in the url used to visit the page.
So is it in the same directory?
I suspect the majority of your problems are from the files not being found and you don’t notice it as openSUSE is by default set to suppress them as they form a possible security risk. I changed the settings myself to show any error not matter how small it is.
For testing it would be a good idea to enable it either trough editting the servers configuration (that’s what I did) or by manually setting it in the file itself trough PHP by using the error_reporting function.
Seems like you’re trying to filter out possible security hazards like trying to go up a directory. A better way is to only allow certain values, I’ll just give you an example along with the previously mentioned error reporting.
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
if( isset( $GET'nfn'] ) )
{
switch( $GET'nfn'] )
{
case 'about':
case 'news':
case 'contact':
include( $GET'nfn'].'php' )
break;
default:
include( 'Sorry the page you have requested could not be found.' );
break; //<- This break isn't needed as it's the end of the switch.. but good practice.
}
}
else
{
include( 'news.php' );
}
That would include news.php, contact.php, about.php if they’re present in the same directory as the file itself.
Hope you don’t take this as an offense, but your HTML is horrendous!
Tables shouldn’t be used for layout
You’re using some ancient tags, if you’re already using a stylesheet (css.css) why don’t you do the styling in there?
For example
body
{
background-color: #ffcc00;
}
img
{
border: 0;
}
instead of setting it on the body element.
It’s going to save you a lot of time if you ever want to change the design.
You may want to look at the XHTML/CSS/PHP sections of w3schools which has many excellent examples.
I did not actually test any of the code, so it might not be free of errors
anyway I tried putting in what u said an it just shows the same thing :S just my layout with a blank part to it where the news and content is suppose to show up. my new.php and other pages are all in the same directorys as index.php. maybe I have to install a certain file still for php?
but if the php menu code works I dont see why my news and content aren’t showing up. I also grabed an index.php file from a website I have running an it has the same php coding. I replaced it to see if my content would show up in there also and nothing appeared again :S this is very strange.
I’m kinda new to all this so yea… how would my code look if I were to put in thos echo codes in? I tryed restarting comp thinking there was just some error an ya…still same thing is happening. No content shows up, just my layout an menu. I also did try puttin the echos in there but nothing shows up also :S but just to make sure I’m putting it in the right place can u show me what it will look like please? thanks
P.S I also viewed source code an the php code shows up on it :S isnt it suppose to be hidden??