citrn Posted February 29, 2008 Share Posted February 29, 2008 Hi there! I am a novice when it comes to PHP, hence the reason why I'm having trouble with such a simple aspect of it. I am creating a new website for my company and I am using an index.php file for the main structure of the site as well as the header and navigation. I want to use PHP to include seperate files that will appear in the main content area of the page. This is what I have placed where I want the content to go: <?php include("$id.html"); ?> With the above code, I should be able to navigate to a specific page by using a URL such as http://www.domain.com/index.php?id=page I also need to have a specific page (welcome, news, etc.) load automatically when accessing index.php, so I have placed the following code above my HEAD tag: <? if ( $id=='' ) { $id="main"; $l="?"; } else { $id="$id"; } ?> The above code does work in the sense that when I access index.php, main.html appears in the main content area. However, the problem I am facing now is that any other file I try to include, results in main.html appearing instead of any other page. For example, if I want index.php to include news.html, I should use the URL http://www.domain.com/index.php?id=news , but main.html keeps coming up. No errors or warnings are being displayed. I am sure I have made an error somewhere in the second code, but I cannot solve this problem. Your kind assistance will be greatly appreciated. Thank you, Robert Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 <?php if (isset($_GET['id'])) { $id = $_GET['id']; if (file_exists("$id.html")) { $page = "$id.html"; } else { $page = "main.html"; } } else { $page = "main.html"; } ?> Then simply use.... <?php include $page; ?> where you want the content to appear. Quote Link to comment Share on other sites More sharing options...
citrn Posted March 1, 2008 Author Share Posted March 1, 2008 Thank you very much Thorpe! You have saved me a lot of time and inconvenience. Your help is much appreciated. Robert 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.