Jump to content


Photo

include from outside web directory


  • Please log in to reply
5 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 August 2006 - 12:38 AM

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

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

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

file.inc
<?php
$a = 'whatever';
?>

file2.inc
<?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.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 04 August 2006 - 12:48 AM

Where is the file calling it, in relation to the include file? One level up? In another folder?
PHP Ninja

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 12:50 AM

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
Tell me the problem, I will try tell you the solution

#4 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 August 2006 - 12:55 AM

Where is the file calling it, in relation to the include file? One level up? In another folder?

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

Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 01:04 AM

ahhh, it should be in the public htm folder mate
Tell me the problem, I will try tell you the solution

#6 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 August 2006 - 01:11 AM

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/?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users