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
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
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

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/?
Link to comment
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.