Jump to content

include from outside web directory


johnnyk

Recommended Posts

Does this have anything to do with PHP? Maybe not. Maybe it doesn't make sense at all.

[code]
<?php
require('/web/directory/file.inc');

require('/web/differentdirectory/file2.inc');
?>
[/code]

[u]file.inc[/u]
<?php
$a = 'whatever';
?>

[u]file2.inc[/u]
<?php
echo $a;
?>


So the problem is that file2.inc will not echo "whatever" (as if $a isn't set). If I did the same kind of thing within the /web/ folder, it works fine. I hope I'm making sense.
Link to comment
https://forums.phpfreaks.com/topic/16503-include-from-outside-web-directory/
Share on other sites

I have just done a test
I have a directory set up
/folder1/file1.inc
/folder2/file2.inc
/inc.php

file1.inc contains
<?
$a = "testing";
?>
file2.inc contains
<?
echo $a;
?>

inc.php contains
<?
require("folder1/file1.inc");
require("folder2/file2.inc");
?>

I load the page and I get
testing
So there is nothing wrong that i could see
using require, if the file did not include (wrong dir or something) there will be an error
[quote author=Caesar link=topic=102929.msg409250#msg409250 date=1154652505]
Where is the file calling it, in relation to the include file? One level up? In another folder?
[/quote]
I don't think I understand your question, but I'll try to answer.

Here's how it looks:
The file that is including the other 2 is /home/username/cron/main.php
file1.inc is /home/username/public/includes/file1.inc
file2.inc is /home/username/public/webmaster/includes/file2.inc

I know that main.php includes both correctly, but the variables set in file1.inc is not accessible in file2.inc
The problem with that, though, is that if someone finds out the location of main.inc, they could run the cron, and that would be bad. I'm using a host and it's not like I can put the cron behind a htpasswd protected folder or anything.

Also, why does it need to be in /public/?

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.