views:

25

answers:

2

Hi guys,

I am trying to locate the location of file being displayed in php.

I have a small file which can be included by any file wither from root or from inside any folder.

i need to print out the location of the.

for long explanation: my config file is config.php located in root location of website i.e localhost/site1/test/. It contains print $_SERVER['SCRIPT_NAME']. it is being included by index.php in root location and also by database.php inside the includes folder of root.

I get two different result:

  1. localhost/site1/test/, when i include config.php in index.php

  2. localhost/site1/test/includes, when i include config.php in database.php

I would like to get localhost/site1/test in both cases. So what can be the choice instead $_SERVER['SCRIPT_NAME']

A: 

Try dirname(__FILE__) (or __DIR__ if using PHP >= 5.3).

http://php.net/manual/en/language.constants.predefined.php

webbiedave
Its giving me absolute path. i want something like web browsable like localhost/... not c:/abc/xyx/
KoolKabin
A: 

Try this: print_r($_SERVER) you will surely find what you are looking for in that array.

Update:

<?php
print_r($_SERVER['HTTP_HOST'].'/'.$_SERVER['SCRIPT_NAME']);
?>
Tom
sorry i am not getting the one... plz help
KoolKabin
`print_r($_SERVER['HTTP_HOST'].'/'.$_SERVER['SCRIPT_NAME'])`
Tom