DenverR Posted August 17, 2010 Share Posted August 17, 2010 my current code for getting a page is <?php $page = $_GET['page']; //Gets the (page=) from the URL if($page){ $site = file_exists($page.'.html') ? $page.'.html' : 'home.html';} else{ $site = 'home.html'; // Else include the default home.php file. } include($site); ?> the problem with it is it only checks for html pages. I would like to have it check for html then php pages and it pull up whichever is valid. i tried to do it myself but im a php n00b. pls help <?php $page = $_GET['page']; //Gets the (page=) from the URL if($page){ $site = file_exists($page.'.html') ? $page.'.html' : 'home.html';} elseif $site = file_exists($page.'.php') ? $page.'.php' : 'home.html'; else{$site = 'home.html'; // Else include the default home.php file. } include($site); ?> ^^ is what i did. any help will be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 17, 2010 Share Posted August 17, 2010 I would never use the file name/path as a GET variable. You are opening yourself up to exploitation. But,this should do what you ask: $pageExtensions = array('htm', 'html', 'php'); if(isset($_GET['page'])) { $page = $_GET['page']; //Gets the (page=) from the URL //Check page against each extension until a match is found foreach($pageExtensions as $ext) { $filepath = "{$page}.{$ext}" if(file_exists($filepath) { $site = $filepath; break; } } } if(!isset($site)) { $site = "home.html"; } include($site); Quote Link to comment Share on other sites More sharing options...
DenverR Posted August 17, 2010 Author Share Posted August 17, 2010 thanks for the reply! i got this though Parse error: syntax error, unexpected T_IF in /home/***/public_html/***/index.php on line 132 Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 18, 2010 Share Posted August 18, 2010 Read my sig. The only thing that jumps out at me is there needs to be a semi-colon at the end of this line: $filepath = "{$page}.{$ext}" 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.