Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.