Jump to content

[SOLVED] Include Help


jptristam

Recommended Posts

I don't really know how to word this, but here we go.

 

I want to have a PHP include on one page, so I can have ONE homepage as a template. So when I type in http://url.com/index.php?page=about.html it brings me to about. But I also want the script to get index.php?page=news.html defaulty. So if I go to http://url.com it goes to index.php?page=news.html, but when I click any other other link it goes there.

 

Kind of a rough explanation, but any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/143328-solved-include-help/
Share on other sites

Okay, we're going to use GET variables, which are the ones in the url.

 

So, if I visit foo.com/bar.php?var=value, I can do the following:

<?php
echo $_GET['var'];
// this will show "value"
?>

 

So, in your case we can do a few things... a switch statement or use arrays

 

I'd recommend going with arrays, as it's the easiest to update.... let me get you some code real quick. If you have access to the server, play around with trying the code above

Link to comment
https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751752
Share on other sites

<?php
// get the URL variable
$pageVar = $_GET['page'];

// create an array of acceptable pages the user can load:
$acceptable = array('main', 'about', 'news', 'contact');

// let's check to see if the variable in the url is in the array or not:
if(!empty($pageVar) && in_array($pageVar, $acceptable)) {
// load the page


} else {
// that page is invalid!
// we can show an error page, or redirect the to the 
// default page


}
?>

 

I'm not sure how you want to include the pages, but that's the basic syntax

Link to comment
https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751754
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.