Includes Error Message

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Includes Error Message

Post by seandisanti » Fri Mar 15, 2013 3:21 pm

It's because you're using url's for your includes instead of relative paths. You can do that (but shouldn't) by modifying your php.ini or using ini_set() to set allow_url_include to 1. it's better to use relative paths, or a getRoot() function that lets you use paths based on your root, regardless of where you're calling from. That's what i typically do. here's a push in that direction...

Code: Select all

/*
 * 
 * function getRoot
 * Parameters:
 *      $uri = string path of the calling file; passed automatically from layout_top.php
 * Returns:
 *      on success: string value to jump from current file to /root/
 *      on fail:    
 */

function getRoot($uri = '') {
    if ($uri == '') {
        $uri = $_SERVER['PHP_SELF'];
    }
    $depth = substr_count($uri, '/') - 1;
    $root = '';
    for ($x = 1; $x <= $depth; $x++)
        $root = '../' . $root;
    return $root;
}
 
and then you can access http://yourdomain/whatever/random.php like so:

Code: Select all

include (getRoot() . '/whatever/random');

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Includes Error Message

Post by seandisanti » Mon Mar 18, 2013 7:27 am

personally I use it in a functions.php file that i include in the head section of pages.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests