Get a file and add it example: news.php?filename

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!

Moderator: General Moderators

Post Reply
DM01
Forum Newbie
Posts: 2
Joined: Mon Aug 17, 2009 1:20 pm

Get a file and add it example: news.php?filename

Post by DM01 »

I've been messing with php for a few weeks now and haven't been able to find this answer.

Basically what I'm trying to do is make a news template for my site and add an article to it so I don't have to make a page for each article. I was thinking news.php?filename then whatever the file name do the include command on the page. Any help would be appreciated.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Get a file and add it example: news.php?filename

Post by jackpf »

Why not use a database?
DM01
Forum Newbie
Posts: 2
Joined: Mon Aug 17, 2009 1:20 pm

Re: Get a file and add it example: news.php?filename

Post by DM01 »

Databases are out of my league at the moment. I'm just trying to save myself a ton of page edits if I need to add something to a template and my articles start reaching the 10-20 range.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Get a file and add it example: news.php?filename

Post by jackpf »

Well...you're probably setting yourself up for more work in the long run by not using a database....

But what are you having trouble with?

You could do this:

Code: Select all

//all your formatting
$tpl = basename($_GET['filename']);
$tpl = ((in_array($tpl, array('valid', 'template', 'files')) ? $tpl : 'default_template').'template_extension';
include $tpl;
//more formatting
Post Reply