AKholic Posted April 8, 2011 Share Posted April 8, 2011 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"); } ?> Quote Link to comment Share on other sites More sharing options...
drisate Posted April 8, 2011 Share Posted April 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.