December 19, 200718 yr if ($_GET['page'] == NULL) { include('main.php'); } else { include($_GET['page']); } I'm trying to achieve the same effect as used by tip.it :? This works when I have ?page=somepage.php, but throws an error when it isn't there. The above was an attempt to get around that, so that I can visit my homepage by sitename/ rather than sitename/?page=main.php
December 19, 200718 yr Try this instead : if ($_GET['page'] === NULL) { include('main.php'); } else { include($_GET['page']); }
December 19, 200718 yr Or try if (!isset($_GET['page'])) { include('main.php'); } else { include($_GET['page']); } Last.fm Signature Overlays
December 19, 200718 yr Or try if (!isset($_GET['page'])) { include('main.php'); } else { include($_GET['page']); } Could also probably do it the other way around : if ($_GET['page']) { include($_GET['page']); } else { include('main.php'); } Or : if (is_null($_GET['page'])) { include('main.php'); } else { include($_GET['page']); }
December 19, 200718 yr Try this instead : if ($_GET['page'] === NULL) { include('main.php'); } else { include($_GET['page']); } Personally I would use if(!empty($_GET['page'])) { require($_GET['page']); } else { require('main.php'); } empty() works better then isset() in this case and personally I always use require() instead of include(). [hide=Drops]Dragon Axe x11Berserker Ring x9Warrior Ring x8SeercullDragon MedDragon Boots x4 - all less then 30 kcGodsword Shard (bandos)Granite Maul x 3Solo only - doesn't include barrows[/hide][hide=Stats][/hide]
December 19, 200718 yr Could also probably do it the other way around : if ($_GET['page']) { include($_GET['page']); } else { include('main.php'); } The above is my preferred method. You must include some kind of is_file() check to a specific directory with the pages in it or limit the include to a certain set of files if you do use any of the posted snippets though. If you don't, you're just asking for someone to come along and use the get method to find ways into your sensitive or OS related files.
December 19, 200718 yr Could also probably do it the other way around : if ($_GET['page']) { include($_GET['page']); } else { include('main.php'); } The above is my preferred method. You must include some kind of is_file() check to a specific directory with the pages in it or limit the include to a certain set of files if you do use any of the posted snippets though. If you don't, you're just asking for someone to come along and use the get method to find ways into your sensitive or OS related files. if ($_GET['page'] && preg_match('/.php/',$_GET['page'])) { include($_GET['page']); } else { include('main.php'); } Eh? (Regular expression matching isn't my favorite thing to do, I can never remember all of the patterns and stuff) Last.fm Signature Overlays
December 19, 200718 yr This is more what I was shooting for. The code I use is a bit different because I use mod_rewrite, but it's the general idea. // If no page, use the default if (!$_GET['page']) { include('pages/default.html'); } // Include page if we know its a web page we want to include elseif (is_file("pages/".$_GET['page'].".html")) { include("pages/".$_GET['page'].".html"); } // Choke and tell them it doesn't exist else { echo 'Page not found'; } This limits the ?page= setup to just files found in your /pages/ directory, which stops any browsing of other files you may not want being spit out by include() or require(). If it isn't in that folder, it doesn't get used.
Create an account or sign in to comment