stormx Posted December 28, 2008 Share Posted December 28, 2008 Hey guys, I've been trying to figure this one out for a long time. I've created a script to include .php files if a session is alive, only problem is that it's not including it from the right location. i think like 2 & 3 have got something to do with it, here is my script: <?php $page = $_GET['page']; $page_include = "/page_include/$page"; if($page) { if(file_exists($page_include.'.php')) { if($page == "index") { echo '<h1>Access Denied</h1>You cannot view this page directly.'; } else { if($page == "login_action") { include('/page_include/login_action.php'); } else { if($page == "password_recover") { include('/page_include/password_recover.php'); } else { if(isset($_SESSION['360net_id'])) { include($page.'.php'); } else { include '/page_include/login_layout.php'; } } } } } else { echo '<h1>404 Not Found</h1> </BR> <h4 class="special">Not Found</h4>'; } } else { include('/page_include/login_layout.php'); } ?> Please help me out Cheers. Link to comment https://forums.phpfreaks.com/topic/138625-php-include-issue/ Share on other sites More sharing options...
Mchl Posted December 28, 2008 Share Posted December 28, 2008 Try: $page_include = "./page_include/$page"; Link to comment https://forums.phpfreaks.com/topic/138625-php-include-issue/#findComment-724817 Share on other sites More sharing options...
wildteen88 Posted December 28, 2008 Share Posted December 28, 2008 Its to do with how you're including you files. Never start file paths with a / as this tells PHP to load the file from the root of the file system (not your sites document root). How I'd do what you're trying to achieve: <?php if(!isset($_SESSION['360net_id'])) { include '/page_include/login_layout.php'; } elseif(isset($_GET['page'])) { // list all pages that can requested by the user $requestable_pages = array( 'login_action', 'password_recover' ); $page_include_dir = $_SERVER['DOCUMENT_ROOT'] .'/page_include/'; if(in_array($_GET['page'], $requestable_pages)) { include $page_include_dir.$_GET['page'].'.php'; } } else { echo '<h1>404 Not Found</h1></BR> <h4 class="special">Not Found</h4>'; } ?> Link to comment https://forums.phpfreaks.com/topic/138625-php-include-issue/#findComment-724818 Share on other sites More sharing options...
stormx Posted December 28, 2008 Author Share Posted December 28, 2008 Hey wildteen88, I tried your script but login_layout.php cannot be found.. I get the 404 error off the script. All the other pages I try though it just show up as blank and have no source code, do you reckon you could help me out more? Link to comment https://forums.phpfreaks.com/topic/138625-php-include-issue/#findComment-724820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.