Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include and path

Status
Not open for further replies.

nego78

Programmer
Jun 13, 2004
129
PL
Hi
i'm including few files in php

let's say that main program is in
/var/
it's include 2 files

Code:
include('/var/[URL unfurl="true"]www/tsest/dir1/dir2/name1.php');[/URL]
include('/var/www/tsest/dir1/dir2/name2.php');

how can i check inside name1.php path to this included file ?

in name1.php code:
Code:
echo $_SERVER['PHP_SELF'];
gives me /var/
is it possible to guess a path to name1.php?

gry online
 
I'm not sure exactly what you are trying to get...
what is the context here, what are you trying to accomplish?

"is it possible to guess a path to name1.php?" makes me think that you are worried that people will find and read you include files. If this is the case try adding the following code to the top of your include files

// this should not be called directly
if( basename($_SERVER['SCRIPT_NAME']) == "include_file_name.php")
{
header("Location: " . " . $_SERVER['HTTP_HOST']);
exit(0);
}

***************************************
J. Jacobs
 
No, i'm not afraid o finding my include files.
I'm using similiar technique to block pages other than index.php.

What i'm trying to acomplish is:

/index.php
/catalog1/catalog11/name.php
/catalog1/catalog11/tmpl.txt


in index.php i include
/catalog1/catalog11/name.php
in this file i execute code
file_gets_content(PATH . tmpl.txt)

BUT

i don't know exactly PATH to this txt (inside name.php)
i only know that tmpl.txt is in the same directory that name.php
So - is anyway to check PATH to name.php inside name.php ?
I can't pass it through variable. I need to achieve it via native function but today i know that is impossible.

Thanks for help :)



gry online
 
require_once($_SERVER['DOCUMENT_ROOT']."/includes/db.php");

From what I'm gathering, that will work. What you're saying is that the relative path to the include file changes when you use files in sub-directories....that code will find the same file, not matter what directory the code that's calling it is in.

***************************************
J. Jacobs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top