debbie-g85 Posted April 30, 2011 Share Posted April 30, 2011 This might be a very easy problem to solve. I am literally brand new to php. I am trying to create a simple site that will load content depending on what page 'id' is in the URL and if it doesn't exist to show a page for that scenario. eg index.php?id=1 will show the page 1.php It works fine apart from showing an error when there is no id at all, eg www.website.com will show an error but www.website.com/index.php?id=1 will show a page I want to be able to show the homepage if there is no 'id' at all. <?php $id = $_GET['id']; if(file_exists("./".$id.".php")) { include ("./".$id.".php"); } else { include ("404.php"); } ?> Any help is appreciated Thanks Quote Link to comment https://forums.phpfreaks.com/topic/235178-simple-dynamic-content-site-help/ Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 Add an if statement which checks to see if $_GET['id'] isset. If it does then set $id to the value of $_GET['id']. Otherwise set $id to 1 The above translated into PHP code $id = isset($_GET['id']) ? $_GET['id'] : 1; Note the ?: syntax is called a ternary operator (an in-line if/else statement) Quote Link to comment https://forums.phpfreaks.com/topic/235178-simple-dynamic-content-site-help/#findComment-1208606 Share on other sites More sharing options...
debbie-g85 Posted April 30, 2011 Author Share Posted April 30, 2011 Works fine, thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/235178-simple-dynamic-content-site-help/#findComment-1208608 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.