January 12, 200818 yr 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]
January 12, 200818 yr <?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
January 12, 200818 yr <?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'); } ?>
January 13, 200818 yr Heh, whoops. That wouldn't have worked all too well; thanks for catching it :P Last.fm Signature Overlays
Create an account or sign in to comment