Php website layout help

hello I made a index.php page an check it on localhost to see if things show up properly. here’s what my code looks like

<html>
<head>
<title>Title Here</title>
<link rel="stylesheet" href="css.css" type="text/css">
</head>


<body bgcolor=#ffcc00>

<table valign="top" align="center" topmargin="0" leftmargin="0">
<tr>
<td align="center" class="nav"><img border="0" src="logo2.jpg"></td>
</tr>
</table>

<table valign="top" align="center" width=755  class="nav">
<tr>
<td valign="top" width="25%" class="solid">
   
<?php include("./mainmenu.php"); ?>



<br>
</td>
	   
<td valign="top" width="100%" class="solid">

<div class="header" align="center">test</div>
<div class="nav">
<?
$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"; 
}
?>
</div>
<br>



</td>
</tr>





<table valign="top" align="center" width=760>
<tr>
<td align="center" class="header" width="760">
Layout By:<a href="#" target="_blank">test</a>   
test<a href="#" target="_blank">test</a></div>
</td></tr>
</table>
</body>
</html>

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!

  1. Tables shouldn’t be used for layout
  2. 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

thanks for the help and info dude.

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.

Did you try viewing the sourcecode of the page itself in your browser? Does the content of the page being included trough php itself show up in there?

Is it not doing what it has been told to do?

Which is if it is set show the other 3 if not show news.php. Not really a coder but to me it is doing what it has been told.

Perhaps a little clarity of what you want it to show when set and not set.

If nothing helps put lines, like this:


echo "first IF.";
echo "second IF.";

inside your IF statements, and after you will be 100% sure where your program stops.
:wink:

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??

ok I just figured out the problem :S just a simple error right at the start but I didn’t know this would make such a huge difference.

<?
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

$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"; 
}
?>

change the <?

I put in <?php

then everything showed up :S

It’s optional. How the PHP code begins, it depends on your PHP configuration (we didn’t know what was yours :)).
Good coding! :slight_smile:

thanks and thanks everyone for your help :slight_smile: