Forum Moderators: coopster
I am currently creating a website as a first time PHP'er. I understand most of it, but am still having problems with linking pages correctly with include();
Main site is index.php, which links to my header.php and other php pages. When I include one of the files, it will show everything just fine, however it will not link to anything OTHER than the page.
My CSS is in a diffrerent folder as well as my images, and they are all broken.
After doing some research, I realized that PHP has some realy fits with paths, since it's server side, and doesn't like linking to directories until you show it exactly where to go. Here's an exerpt of my site code, trimmed down, to show you what I'm doing.
Thanks if you can help.
(Since the code function sucks on this site:)
---code---
include('header.php');
//The pages you wish to display
$pages = array(
'seeds' => 'seeds.php',
'contact'=> 'contact.php',
'forum'=> 'forum.php',
'support' => 'support.php'
);
//if the file exist, and is in the array it will display the file.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include ($name);
}
}
}
else {
//We will now display the home page, but if some enters in the wrong name it will also display this page.
include("home.php");
}
---/code---
This file is on webroot. CSS is in /css and images are in/images.
The files included are php files with no php in them, and are straight html. The included files all link to seperate directoies mentioned above.
Index.php ->
include('header.php');
//The pages you wish to display
$pages = array(
'seeds' => 'seeds.php',
'contact'=> 'contact.php',
'forum'=> 'forum.php',
'support' => 'support.php'
);
//if the file exist, and is in the array it will display the file.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include ($name);
}
}
}
else {
//We will now display the home page, but if some enters in the wrong name it will also display this page.
include("home.php");
}
For instance let's look at header.php ->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="CSS/Level1_Verdana.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="10" marginwidth="0" marginheight="10">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="8"><img src="images/header.jpg" width="800" height="80" alt="Complete Web Services" /></td>
</tr>
<tr>
<td><img src="images/index_sub_left.jpg" width="213" height="30" alt="" /></td>
<td><img src="images/index_stretch.gif" width="37" height="30" alt="" /></td>
...etc
Now, the IMG tags should be showing their sources, but they are just showing broken links. I don't know the problem :(
Also, index.php and header.php are both on the webroot. The image files are under /images
[edited by: jatar_k at 4:40 pm (utc) on June 7, 2005]
[edit reason] no urls thanks [/edit]