Jump to content

[SOLVED] brutal issues including files (include())


play_

Recommended Posts

Ok.

i have the document root set to = $documentRoot = 'http://localhost/Decay/contests/mmporg2/

you can think of it being just http://localhost if you'd like. doesn't change the problem.

 

[localhost]

  |__[admin]

      |--menu.php

  |__[includes]

      |--header.php

|--index.php

 

 

under the root folder, i have:

a folder called 'admin' (menu.php inside)

a folder called 'includes' (header.php inside)

a file called index.php

 

 

in index.php, i include header.php.

but from header.php, i include menu.php

 

 

error:

Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 37

Warning: include(http://localhost/Decay/contests/mmporg2/admin/menu.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 37

 

any thoughts? include() has been giving me a really hard time lately.

 

ps: im using absolute path as the include paremeter

 

 

ps: if i create an index.php inside the 'admin' folder, i get errors too:

arning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 37

Warning: include(http://localhost/Decay/contests/mmporg2/admin/menu.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 37

 

pss: 'ini_set('allow_url_fopen', 'on');' does not work also

 

the code should parsed from the original file path

thus if you include menu.php from header.php include it as if were included directly from index.php

 

index.php contents

 

include "header.php";

 

header.php contents

 

include "menu.php";

 

have u tried it like that?

"header.php contents

 

include "menu.php";"

 

do you mean include "./admin/menu.php" ?

 

because yes, i have.

 

and it works.

 

the problem, index.php under 'admin' folder will give an error

 

 

it's simple. i just want

include('http://localhost/Decay/contests/mmporg2/admin/menu.php');  (in header.php)

to work. i cant believe absolue URLs are giving errors

tried to recreate and not having much success

 

i made this

 

root

  admin

    menu.php

  includes

    header.php

  index.php

 

INDEX.PHP

<?
include "includes/header.php";
?>

 

HEADER.PHP

<?
include "admin/menu.php";
?>

 

MENU.PHP

this is the menu

 

and all is well

 

if index.php is in "admin" folder

 

HEADER.PHP

<?
include "menu.php";
?>

 

 

allow_url_fopen can only be altered directly through the ini

 

are you on shared platform, what version php?

 

can you put code of each of files on here?

I tried this and it worked.

 

I believe that because the original index.php included header.php, it keeps index.php's folder as the "root".

 

INDEX.PHP

******************************

<?PHP

echo "<BR>INDEX.PHP<BR>";

include("includes/header.php");

?>

 

HEADER.PHP

******************************

<?PHP

echo "<BR>HEADER.PHP<BR>";

include("admin/menu.php");

?>

 

MENU.PHP

******************************

<?PHP

echo "<BR>MENU.PHP<BR>";

?>

right, that's how it works for me

 

I tried this and it worked.

 

I believe that because the original index.php included header.php, it keeps index.php's folder as the "root".

 

INDEX.PHP

******************************

<?PHP

echo "<BR>INDEX.PHP<BR>";

include("includes/header.php");

?>

 

HEADER.PHP

******************************

<?PHP

echo "<BR>HEADER.PHP<BR>";

include("admin/menu.php");

?>

 

MENU.PHP

******************************

<?PHP

echo "<BR>MENU.PHP<BR>";

?>

There's an index.php in both the root folder, and another one under 'admin' dir.

 

PHP 5.2.0

MySQL 5.0.27

running all on my windows box.

 

as for a code of each files, there's alot more to them than that. but the include is the problem.

 

 

Problems with the solution you provided:

 

"include('./admin/menu.php');" will work fine if vieing index.php under the root folder.

however, on the index.php under 'admin' folder, i must use include('../admin/menu.php');

 

But that is obvious.

But gives errors. So im trying to use absolute urls.

 

 

ps: i appreciate your help :)

if anyone would like,

http://www.decay.nu/help.zip....has all the files.

 

try opening index.php from the root folder. works fine.

but if you open the index.php under the admin folder, header.php gives you an error because its not including menu.php

I tried this and it worked.

 

I believe that because the original index.php included header.php, it keeps index.php's folder as the "root".

 

INDEX.PHP

******************************

<?PHP

echo "<BR>INDEX.PHP<BR>";

include("includes/header.php");

?>

 

HEADER.PHP

******************************

<?PHP

echo "<BR>HEADER.PHP<BR>";

include("admin/menu.php");

?>

 

MENU.PHP

******************************

<?PHP

echo "<BR>MENU.PHP<BR>";

?>

 

Right. but the index.php under 'admin' dir will cause errors.

in header.php..

 

include('./admin/menu.php'); <--- works

 

but this doesnt work, why?:

include('http://localhost/Decay/contests/mmporg2/admin/menu.php');

 

error:

Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 38

Warning: include(http://localhost/Decay/contests/mmporg2/admin/menu.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes\header.php on line 38

 

line 38:

include($root . 'admin/menu.php');

allow_url_fopen has been on, i just checked.

 

Anyways, yes i realize there are fixes around, but that makes the code look dirty =(

 

 

And thanks for your solution. Although it works, it's inconvenient since i need to include other files through the site =/

 

there has to be a solid, consistent way of solving this. still trying to figure out why absolute URLs dont work.

Ok. Found a Solution. (thank god).

 

In header.php, i have this:

$fullDirPath = dirname(__FILE__);

 

Because that gets excecuted in header.php, $fullDirPath will always be:

C:\Program Files\EasyPHP 2.0b1\www\Decay\contests\mmporg2\includes

 

Therefore, i can work from there.

 

I included menu.php like this:

include($fullDirPath . '/../admin/menu.php');

 

So, for now, this solved. I have a feelings it's gonna comeback to haunt.

 

Thanks all that have helped :)

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.