views:

57

answers:

3

Hi,

What I trying to do is to define a constant variable in a config file:

DEFINE("PATH", dirname(__FILE__) . "/");

So that, when I want to "include" or redirect, I could do this:

include(PATH . "filename.php");

or

header("location: " . PATH . "logout/php");

But when I try doing an echo of PATH, I get this result:

/home/myDOMAIN/public_html

Am I declare the constant wrongly? (To be honest, I copy that code from Wordpress config file)

A: 

I guess this is your path on the server side.

aviv
So what I am doing is wrong? I try "include_once", but I got fatal_error message
web_starter
+2  A: 

Update:

Try this:

// sets site path for inclusion of files
define ('PATH', $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']));

More Info:

http://php.net/manual/en/reserved.variables.server.php

Sarfraz
Hi, i tried include the prefix, very strange, I got this result:/home/myDOMAIN/public_html/home/myDOMAIN/public_html
web_starter
@web_starter: See my updated answer please.
Sarfraz
@sAc: Great. It works now
web_starter
@web_starter: That is good news :)
Sarfraz
+1  A: 

The __FILE__ magic constant contains a file system path, not a URL. You'd need to create two different constants, e.g. FS_ROOT for includes and WEB_ROOT for URLs.

In many cases, you already have a builtin value in the $_SERVER array that can help you. Run print_r($_SERVER) to find out.

Álvaro G. Vicario