Earpy Posted January 12, 2008 Share Posted January 12, 2008 Well, I've made a dynamic PHP script which includes html files dynamicly and im wondering how to tweak it a little. The script currently only includes HTML files and im wondering how to edit it so that it will include both. So I want it to look at the parameter in page and search for the HTML, if that is not there, search for PHP, and if PHP is not there display the error page. Any solutions? Thanks in advance for any help [hide=Click here for code]<?php if (isset($_GET['page']) && $_GET['page'] != "") { $page = $_GET['page']; if (file_exists('pages/'.$page.'.html')) { @include ('pages/'.$page.'.html'); } elseif (!file_exists('pages/'.$page.'.html')) { include_once('pages/error.html'); } } else { @include ('index.php?page=news.html'); } ?> [/hide] Link to comment Share on other sites More sharing options...
Errdoth Posted January 12, 2008 Share Posted January 12, 2008 <?php if(isset($_GET['page']) && $_GET['page'] != "") { $page = $_GET['page']; if(file_exists('pages/'.$page.'.html') || file_exists('pages/'.$page.'.php')) { include('pages/'.$page.'.html'); } else { include('pages/error.html'); } } else { include ('index.php?page=news.html'); } ?> Last.fm Signature Overlays Link to comment Share on other sites More sharing options...
MageUK Posted January 12, 2008 Share Posted January 12, 2008 <?php if(isset($_GET['page']) && $_GET['page'] != "") { $page = $_GET['page']; if(file_exists('pages/'.$page.'.html') || file_exists('pages/'.$page.'.php')) { include('pages/'.$page.'.html'); } else { include('pages/error.html'); } } else { include ('index.php?page=news.html'); } ?> If the PHP page exists, won't that script try and include the HTML page that won't exist? If I pass index.php?page=mypage and mypage.php exists, but mypage.html does not, this script will see mypage.php exists and then try to include mypage.html, which doesn't exist, so it needs a little work. A note if this code is to be placed inside index.php itself : The code is a bit inconsistent (not your fault since the OP makes it look like the code wouldn't be included in index.php but it probably will be), in the first instance you decided the variable "page" would be just the name of the file without extension. Further down in your error compensation code you've set page to "news.html" which would cause an endless loop. You also don't want to be including index.php within itself. We also need to declare the variable $page as equal to our GET. @ OP, if this code is for your index.php page, then this may work a little better : <?php if(isset($_GET['page']) && $_GET['page'] != "") { $page = $_GET['page']; if (file_exists('pages/'.$page.'.html')) { include ('pages/'.$page.'.html'); } elseif (file_exists('pages/'.$page.'.php')) { include ('pages/'.$page.'.php'); } else { include('pages/error.html'); } } else { include('pages/news.html'); } ?> Link to comment Share on other sites More sharing options...
Errdoth Posted January 13, 2008 Share Posted January 13, 2008 Heh, whoops. That wouldn't have worked all too well; thanks for catching it :P Last.fm Signature Overlays Link to comment Share on other sites More sharing options...
Earpy Posted January 13, 2008 Author Share Posted January 13, 2008 Thanks to both of you, solved my problem! :thumbsup: Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now