PHP Environment Variables Undefined -
i having bit of trouble setting , using environment variables in php.
i have php file follows
http://localhost/site/include.php
<?php define("env_location", "http://localhost/site/resources/addition"); ?>
which including in following file
http://localhost/site/home.php
<html> <?php include("include.php"); ?> <body> <?php // bit works echo env_location; // bit works include(env_location . "/test.php"); ?> </body> </html>
but seems lose environment variable when try use in last file including
http://localhost/site/resources/addition/test.php
<?php // fails echo env_location; ?>
why file unable see environment variable? getting following error
notice: use of undefined constant env_location - assumed 'env_location' in /var/www/html/site/resources/addition/test.php on line 3 env_location
what you're doing is:
include "http://localhost/site/resources/addition/test.php";
this includes file over http. means new http request server made (your server making request itself), , new request won't have context other request. it's other independent http request coming web server, nothing shared between them.
it's
- madness include files on http and
- hopefully obvious why doesn't work expect.
you need include file locally, not url:
include "resources/addition/test.php";
probably want define constant file path, not url:
define("env_location", ___dir___);
Comments
Post a Comment