PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've created a script (well, two different ones). The first one is for my index.php page, which is a simple include switch that keeps it to a single page design:
<?php
ini_set('include_path', 'http://mobius_man.t35.com');
switch ($_GET['page']) {
case 'articles':
include('articles.php');
break;
case 'contact':
include('contact.php');
break;
case 'spotlight':
include('spotlight.php');
break;
case 'fan':
include('fan.php');
break;
case 'multimedia':
include('multimedia.php');
break;
case 'links':
include('links.php');
break;
case null:
include('./news/news.txt');
break;
default:
include('error.php');
break;
}
?>
That works fine. Secondly, I have a script that when I want to create pages for these pages (i.e. index -> articles -> page), it makes links on the selected page (articles.php for example). This is ok as well. The problem is, how can I include these links on the page as I do with the index.php and those branch files.
Basically I want the index ->articles.php ->page linked from articles.php to all be a single-page deal.
First, dynamic includes might be a better option than a switch / case - can be much quicker with many cases. You'd need to prefix file names for security if you are opening files based on values passed via GET:
<?php
//Include content
if (isset($_GET['id'])) {
$id = "".addslashes($_GET['id']).".php";
if (file_exists($id)) {
include ($id); //Include chosen page
}
else {
include ("404.php"); //If the file requested does not exist
}
}
else {
include ("start.php"); //Default page
}
?>
lol There is nothing wrong with what he uses, I use the exact same thing. And on most servers I've tested the different page switchers, the difference in script execution is not even a hundredth of a second; so no biggie. And I prefer to define what pages are able to be called instead of allowing anything within a directory, based on the file name. Maybe he does too.
Regarding your article manager, what is wrong with what you're trying to do? And how can we help?
?p=articles which requires articles.php; and within articles.php, you require an article be called from the GET method also. So the URL would be something like ?p=articles&id=2925.