Kynetek Posted March 28, 2007 Share Posted March 28, 2007 Ok. I know what I need is something simple, but I just can't remember exactly what the code for it is. Basically I have a file, my .php file. But what I want to do is make an include that allows me to click a link and it'll include it into the main content table of the page... All I can really remember is that the URL I used to use looked something like this: http://http://free.hostultra.com/~kynetek/index2.php?id=News/News.html If someone could help me i'd be godly greatful... Link to comment https://forums.phpfreaks.com/topic/44607-need-help-fast/ Share on other sites More sharing options...
ted_chou12 Posted March 28, 2007 Share Posted March 28, 2007 $page = $_GET['id']; include("$page"); Ted Link to comment https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216632 Share on other sites More sharing options...
wildteen88 Posted March 28, 2007 Share Posted March 28, 2007 $page = $_GET['id']; include("$page"); Ted That is extremely insecure! I would do something like this: if(isset($_GET['id'])) { $page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['id']; if(file_exists($page)) { include "$page"; } else { die($page . ' cannot be found!'); } } That is much more secure. Link to comment https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216938 Share on other sites More sharing options...
neoform Posted March 28, 2007 Share Posted March 28, 2007 That is extremely insecure! I would do something like this: if(isset($_GET['id'])) { $page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['id']; if(file_exists($page)) { include "$page"; } else { die($page . ' cannot be found!'); } } That is much more secure. errr..... url.php?id=../../../somefile.php You'd be far better off cleansing that variable prior to using it. eg. intval($_GET['id']) or at least stripping out any ".." from it. Link to comment https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216942 Share on other sites More sharing options...
poirot Posted March 28, 2007 Share Posted March 28, 2007 You can use the built-in function basename() to strip the directories http://www.php.net/basename Link to comment https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.