Jump to content

Load PHP pages – help please


AKholic

Recommended Posts

Hi,

 

I am new to PHP, so I’m sure this is a very basic mistake I am making.

I am trying to get different pages to load based on the link that is clicked.  I have a little bit of code to check and make sure the requested page exists and if so to load it, if it doesn’t exist the home.php page should load.  Right now the home.php page is the only thing that will load, even though the other pages do exist.

Any help is appreciated.

 

Here is the code I am using:

 

 

<?php


$page = $_GET['page'];

if ($page)
{
include("Content/".$page.".php");
}
else
{
include("Content/home.php");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/233095-load-php-pages-%E2%80%93-help-please/
Share on other sites

I would recomend you to do something like this

 

<?php

echo '<a href="index.php?page=1">Page 1</a> | <a href="index.php?page=2">Page 2</a><br><br>';

if ($_GET['page']=="1"){
    include("Content/page1.php");
}elseif ($_GET['page']=="2"){
    include("Content/page2.php");
}else{
    include("Content/home.php");
}

?>

 

The way you did it a hacker could change teh value of your $_GET['page'] and include anything

 

Make sure your "Content" directory really has a capital C. It's case sensetive.

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.