Bodhran Posted March 10, 2011 Share Posted March 10, 2011 I am having some real problems with the code in red below which sits in my "index.php" file, and would be very grateful for any help! <?php include("header.php"); include $_GET["view"] . ".php"; include("footer.php"); ?> The links for my "views" (e.g. <a href="?view=page_news">News</a> ) are in my "header.php" file. The whole website works absolutely fine, except when you first arrive on the homepage you get: Notice: Undefined index: view Warning: include(.php) [function.include]: failed to open stream: No such file or directory This is presumably because a link hasn't been clicked yet, thus a "view" hasn't been defined yet, but I have no idea how to get around this! I hope I haven't been too vague with my explanation... Thanks, James Link to comment https://forums.phpfreaks.com/topic/230161-rather-stuck-using-include-_get/ Share on other sites More sharing options...
Bodhran Posted March 10, 2011 Author Share Posted March 10, 2011 I stupidly uploaded my files to the server before properly testing them, so you can see my problem in action at "thehurricanes.co.uk" if it helps! Link to comment https://forums.phpfreaks.com/topic/230161-rather-stuck-using-include-_get/#findComment-1185294 Share on other sites More sharing options...
trq Posted March 10, 2011 Share Posted March 10, 2011 if (isset($_GET['view'])) { include $_GET["view"] . ".php"; } else { // include some default } you'd best check the file exists locally before including it too as this method alone opens a massive security hole. Link to comment https://forums.phpfreaks.com/topic/230161-rather-stuck-using-include-_get/#findComment-1185296 Share on other sites More sharing options...
Bodhran Posted March 10, 2011 Author Share Posted March 10, 2011 Brilliant! Thank you for your help :-) Link to comment https://forums.phpfreaks.com/topic/230161-rather-stuck-using-include-_get/#findComment-1185301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.