[RESOLVED] include files to index
how can i include files to the index site using a menu to navigate with ?q= ??? i'm not sure what this is called but i'm sure someone will know what i mean...
like if you type the link of the site or just index.php?q=users then it will replace the content of my site with the contents of users.php
sorry i can't explain this very well as i don't know exactly what it is...
Re: include files to index
something that works generally like this:
PHP Code:
<?php
$path = "./"; //path to include directory
$extension = ".inc.php"; //I'd use .inc.php rather than just .php to be somewhat more secure
/** get the action **/
//using long if statements, I usually use ternary operators instead
if(isset($_GET['a'])){
if(file_exists($path . $_GET['a'] . $extension)){
//action does exist
$action = $_GET['a'];
}else{
//they tried an action that doesn't exist
$action = "error";
}
}
//if the action wasn't set, set a default
if(!isset($action)){
$action = "main";
}
//we're done our "action logic", so spit out our page 'template'
?>
<html>
<head>
<title>My page</title>
</head>
<body>
<ul id="menu">
<li><a href="?a=main">Home</a></li>
<li><a href="?a=contact">Contact</a></li>
<li>...</li>
</ul>
<div id="content">
<?php
//we are now at the point where we can include our action file
require_once($path . $action . $extension);
?>
</div>
</body>
</html>
that's pretty much it. ask questions if you're confused or need help.
Re: include files to index
this is exactly what i needed, thank you.