Perry| Posted June 14, 2008 Share Posted June 14, 2008 Hello. I am making a site template with php includes, however, I have lots of things I need in the template and I do not know how to do them as I am fairly new to PHP. Here is an idea of what I want to the site look like Yellow areas are the template, red areas are the template but are adverts and the blue area is what is dynamic and will be changed on the page type via creating a new php document, copying the template from a text file on the server then including the file with the data in the specific place. So could someone post example code so I can learn off of it or something :-\ In the blue area I will be using include("./s/file".$_GET['id'].".php") Will it work with the template aswell? I am really new to PHP so I need extra help with all of this. Regards, Perry Quote Link to comment https://forums.phpfreaks.com/topic/110231-making-a-site-template-with-php-includes/ Share on other sites More sharing options...
alvinrow Posted June 14, 2008 Share Posted June 14, 2008 If you want everything to stay the same except the blue area, you may wish to try: <?php if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = 'default'; } if (preg_match('/^[a-z0-9_-]+$/i', $id)) { require('./' . $id . '.php'); } else { die('Invalid Input'); } ?> This will allow you to change the blue area (with a link like index.php?id=foo), whilst not affecting the rest of the index.php template. The preg_match code is to make sure it cannot be exploited. Also, note the 'else', which means that if no ID is called, then it should display 'default'.php (or whatever page you want) Quote Link to comment https://forums.phpfreaks.com/topic/110231-making-a-site-template-with-php-includes/#findComment-565620 Share on other sites More sharing options...
Perry| Posted June 14, 2008 Author Share Posted June 14, 2008 Hello alvinrow. I only need id's on certain pages, not on the main page. It's all a bit confusing. Quote Link to comment https://forums.phpfreaks.com/topic/110231-making-a-site-template-with-php-includes/#findComment-565625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.