hey guys,
I would like to set a default path for my "php root" constant, that will either load by default into my $_SERVER global or simply just load into my php scripts before anything else.
This way I won't have to worry about relative paths and can link to everything absolutely...
for example rather than using:
include('/includes/file.php')
I can use include(ABSPATH.'includes/file.php');
Thanks
Andrew
environmental variables...
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I think your talking about the document root and not php's root directory. If you want this value automatically loaded in all your scripts you could pop the following code in a auto-prepended file by apache, if not simply include a file that defines the path.
Code: Select all
define('ABSPATH', $_SERVER['DOCUMENT_ROOT']);- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
If you're using Apache you can define it in an .htaccess file ... for example ...
That will let you access pages using http://www.domain.com/page/123/page-tit ... -here.html ... the page requested will be page.php?id=123 .. and in that page you can use $_SERVER['mypath'] to get "/path/to/site/".
Code: Select all
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule .* - [E=mypath:/path/to/site/]
RewriteRule ^page\/([0-9]+)\/(.*)$ %{ENV:mypath}page.php?id=$1&%1 [NC,L]