Hoi terug.
Ik heb deze code gebruikt voor het includen om eens te testen maar het werkt niet goed. De pagina die ik wil laten verschijnen kan blijkbaar niet gevonden worden.
Hier is het script zoals ik het in mijn webpagina gebruikt heb:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
/**
* Arrays om errors en content tijdelijk in op te slaan
*/
$aErrors = array();
$aContent = array();
/**
* Array met alle paginas die geïnclude mogen worden,
* de keys stellen de namen van paginas voor en de waarden geven met een boolean
* aan of de pagina statisch (false) dan wel dynamisch (true)
*/
$aPages = array (
'news' => true,
'links' => false,
'bestaat_niet' => false
);
/**
* Directory waarin de paginas zich bevinden
* Extensie die de te includen paginas hebben
*/
$sDir = 'inc/';
$sExt = '.inc.php';
/**
* Is er een pagina opgegeven?
*/
if(isset($_GET['page']))
{
$sPad = $sDir.$_GET['page'].$sExt;
/**
* Is dit een toegestane pagina?
*/
if(array_key_exists($_GET['page'], $aPages))
{
/**
* Bestaat de opgevraagde pagina?
*/
if(file_exists($sPad))
{
/**
* Is de pagina dynamisch of statisch?
*/
if($aPages[$_GET['page']] === true)
{
include($sPad);
}
else
{
$aContent[] = file_get_contents($sPad);
}
}
else
{
$aErrors[] = 'Page does not exist.';
}
}
else
{
$aErrors[] = 'Page is not allowed.';
}
}
else
{
$aContent[] = 'No page entered';
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url(images/F_040.png);
}
-->
</style>
<link href="styles/blackcrucible.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
color: #74A0FF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #74A0FF;
}
a:hover {
text-decoration: underline;
color: #74A0FF;
}
a:active {
text-decoration: none;
color: #74A0FF;
}
a {
font-size: 14px;
}
#include { padding: 10px;
border: 2px solid #EEF7D4;
}
-->
</style></head>
<body bgcolor=#000000 text=#CCCCCC leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<table width="100%" height="80" border="0" class="blackcrucible">
<tr>
<td><img src="images/blackcrucible.png" width="430" height="52" /></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="3" align="center" valign="top" class="stableleft"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="tmenucell"><div align="center">Main</div></td>
</tr>
<tr>
<td class="fnmenucell"><a href="?page=news">News</a> <br /></td>
</tr>
<tr>
<td class="nmenucell">Links</td>
</tr>
<tr>
<td class="nmenucell">Contact</td>
</tr>
<tr>
<td class="tmenucell"><div align="center">Mods & Levels </div></td>
</tr>
<tr class="gamestf">
<td class="gamestf"><img src="images/q3a.jpg" width="125" height="125" /></td>
</tr>
<tr>
<td class="fnmenucell"> </td>
</tr>
<tr>
<td class="fnmenucell"> </td>
</tr>
<tr>
<td class="tmenucell"><div align="center"></div></td>
</tr>
</table></td>
<td height="50" class="welcomecell"><div align="center">WELCOME TO BLACKCRUCIBLE.COM! </div></td>
<td rowspan="3" class="stableright"> </td>
</tr>
<tr>
<td height="816" align="left" valign="top" class="centertable"><div id="include">
<?php
/**
* Outputten van content die tijdens het includen gegenereerd is.
* Fouten staan in $aErrors, de rest van de content in $aContent.
*/
if(!empty($aErrors))
{
echo '<ul>';
foreach($aErrors as $sError)
{
echo '<li>'.$sError.'</li>';
}
echo '</ul>';
}
elseif(!empty($aContent))
{
foreach($aContent as $sLine)
{
echo $sLine;
}
}
?>
</div></td>
</tr>
<tr>
<td height="52" align="right" valign="bottom" class="bottomcell"><h4>DESIGN BY SERGE JAEKEN </h4></td>
</tr>
</table>
</body>
</html>
Je kan het resultaat op deze website zien:
www.blackcrucible.com
Weet er iemand wat ik verkeerd heb gedaan?
Dank bij voorbaat.