Jump to content

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

This is all I got... I want it to go to "index.php?page=main.html" when I go to jptristam.net. Then from there I want to be able to click a link, say about, and go to index.php?page=about.html.

 

I have no PHP currently, I deleted it cause it did not work.

Link to comment
https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751747
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.