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

Link to comment
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.