Jump to content

PHP Include Issue


stormx

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.