PHP Help

I am trying to remember a code I used about 6 years ago to fetch certain pages for my website(I haven’t written code in almost 6 years) and I can’t remember how to do it.

I used to be able to put:

and then a code in the content section of my layout and when clicking on that link(or any of my other links) it would then bring up that page’s content in the content section. My problem is:
A) I don’t remember the PHP code that I should be putting in the content section.
B) I don’t remember what I should be saving the pages as; home.php, home.html?

My website is pixelatedempire.net and if you take a quick look at where I’m trying to pull the content up I’m sure you’ll figure it out very quickly.

Here is my source code(please don’t judge too much, I used to be very organized and wrote nice code but like I said I haven’t touched a piece of code in 6(maybe more years) and a lot of things have not only changed but I’ve forgotten almost everything I used to know):
[php]

Pixelated Empire html, body, #main, #content { height: 100%; margin: 0; padding: 0; border: none; text-align: left; background-color:#ff5b5b; } #main { margin: 0 auto; text-align: left; vertical-align: top; height: 100%; width: 800px; background-color:#c40e0e; } #content { margin: 0 auto; text-align: left; vertical-align: top; height: 100%; width: 784px; background-color:#c40e0e; }
<?php include("index.php?pe="); ?> Content goes here.
[/php]

You can either use a switch or if-elseif statements, something like
[php]
switch($_GET[‘pe’]) {
case ‘home’:
include ‘home.html’;
break;
case ‘contact’:
include ‘contact.php’;
break
default:
include ‘home.html’;
break;
}

if($_GET[‘pe’] == ‘home’) {
include ‘home.html’;
} elseif($_GET[‘pe’] == ‘contact’) {
include ‘contact.php’;
} else {
include ‘home.html’;
}[/php]

Hey, I just registered so I could reply(it wouldn’t let me as a guest)

So I put this in:
[php]

<?php switch($_GET['pe']) { case 'home': include 'home.php'; break; case 'contact': include 'contact.php'; break default: include 'home.php'; break; }

if($_GET[‘pe’] == ‘home’) {
include ‘home.php’;
} elseif($_GET[‘pe’] == ‘contact’) {
include ‘contact.php’;
} else {
include ‘home.php’;
}
?>

[/php]

And then when I loaded my website I got:

Parse error: syntax error, unexpected T_DEFAULT in /home/frostynwinters/pixelatedempire.net/index.php on line 110

When I used to have this code work years ago it was only like 2-3 lines long and I didn’t have to specify the specific pages I wanted to load with it, whenever I clicked one of the links I created above, as long as I had the line of code in the middle it would grab that page and pull it up in that section.

(Sorry if this is a double post, it said I got the verification letters wrong and then when I re-typed them correctly it said I’d already posted it)

Hey, I found the piece of code I was looking for in an email I had sent way back in 2006. The code snippet I was looking for was:

<?php if (empty($_GET['pe'])) { include('home.htm'); } else { include($_GET['pe'] . '.htm'); } ?>

Works like a charm now.

Although, there was an edit that someone had showed me years back to improve security with that where you had to save the pages as _page.htm and it would only load pages with an _ infront of them(thus people couldn`t link yourwebsite.com/index.php?pe=website.com and bring that into the content section). To prevent people from writing a virus on a page and then opening it on your website. Anyone know where I should be putting that _ in this code?

exact same thing I posted earlier :slight_smile: You got an error because there’s a missing ; on the second break in my switch example. Since you want to use if statements, that’s what i’m using below.

A much simpler way of doing it would be
[php]if(isset($_GET[‘pe’])) {
if($_GET[‘pe’] == ‘home’) {
include ‘home.htm’;
} elseif($_GET[‘pe’] == ‘contact’) {
include ‘contact.htm’;
}
}else {
include ‘home.htm’;
}

[/php]
You don’t have to worry about using any additional security measures and it creates a default page

Sponsor our Newsletter | Privacy Policy | Terms of Service