Cannot get value from define function ?

hello everyone,
I try to get value from define function (core php)

I explain my problem :
I have 3 pages.
- index.php
- config.php
- footer.php

index.php :
i include the config.php file ( see code snippet )

config.php :
declare the constant SERVER_WEB by using define function. ( see code snippet )

footer.php : ( see code snippet )
try to show value of constant SERVER_WEB. and this is what i get :

no error is reporting from php.
thanks for all,

//*************** index.php : 
//*************** config.php : 
//*************** footer.php : 

Open in new window

Who is Participating?
beatboxradioConnect With a Mentor Author Commented:
ok, I found a solution :

"When you include it using a URL as above, the file is served from the
webserver which parses the php script as it has a php extension. With
the other extensions, the php code isn't parsed. Try looking at the
URL with a browser and you'll see what I mean.

Your include path should be a physical path to the file e.g:
include ('/usr/local/htdocs/includes/includes.php');"

by using, the physical path, everything works fine !

thx for all !
jausionsConnect With a Mentor Commented:
error_reporting(E_ALL) may not be enough if display_errors if turned off, unless you're looking at the web server's log file.

Add ini_set('display_errors', true) to make sure errors are showing.

You could have a wrong include for instance, or some other errors that are not displayed.
beatboxradioAuthor Commented:
ok i've added new things...

into index.php :
ini_set('display_errors', true);

look into logs of apache and php, and no error is showing.

i will add a new information :
when i call the page footer.php, i use this :

the page is called successfully but the variable SERVER_WEB has no value.

also into php.ini, this is what i get :
allow_url_fopen = On
allow_url_include = On

display_errors = On
display_startup_errors = On
log_errors = On
error_reporting = E_ALL & E_STRICT

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

jausionsConnect With a Mentor Commented:
Double check the config.php you're loading is really the one you expect. For instance is it really in the includes/ sub-folder etc...

An easy way to do check this is to intentionally create a parsing error in the config.php file.

Also make sure the config.php file doesn't overwrite error_reporting set in the index.php.

On a side note, I advise you to always use <?php instead of <? and use <?php echo instead of <?=

beatboxradioAuthor Commented:
ok, i change again my things.

really strange...
//************ index.php
echo TEST;
//******** HTML_PATH works here, value is html/
//**************** footer.php
<?php echo TEST; ?>
//********** value of TEST show in index.php
//********** value of TEST show in footer.php
/** TEST

Open in new window

Roger BaklundConnect With a Mentor Commented:
Maybe short_open_tag is disabled on your server?

In your last example, how is the footer.php called? Directly in the browser, or included from index.php?
The value of an undefined constant will be the name of the costant, i.e. if you did not define TEST, the output of echo TEST; should be "TEST". It should also give a warning about undefined constant.

You can use the defined() function to check if a constant is definied:
beatboxradioAuthor Commented:
for CXR :
the short_open_tag was ON.

but  I found something :

i call footer.php like that :

<? include(HTML_PATH.'footer.php'); ?>
( where HTML_PATH = http://localhost/beatboxradio_v6/html/ )

and like this way, the constant into footer.php TEST doesn't work.

if I replace HTML_PATH by subfolder " html/ " =
everything works fine.

i don't know why by using HTML_PATH the constant don't have the value because
the footer.php file load successfully by using HTML_PATH.


beatboxradioAuthor Commented:
for CXR :
i call footer.php into index.php like :
<? include(HTML_PATH.'footer.php'); ?>

and TEST constant was defined into index.php  like :

Roger BaklundConnect With a Mentor Commented:
Try executing this:

echo phpversion().'<br />';
echo 'allow_url_fopen='.(ini_get('allow_url_fopen') ? 'on':'off').'<br />';
echo 'allow_url_include='.(ini_get('allow_url_include') ? 'on':'off').'<br />';

Including a file using http:// is only allowed if the version is later than 4.3 and both allow_url_* settings are on.

A safer way to include is using $_SERVER['DOCUMENT_ROOT']:


Open in new window

beatboxradioAuthor Commented:
this is what i got :


thx for your new way to include !
Roger BaklundConnect With a Mentor Commented:
Using urls in the include path is for including code from remote servers. Using localhost won't work at all on my windows box, don't know why. I get a timeout. Apache error log says:

"failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

...this is when php tries to connect to localhost over port 80...!?

As a consequence, I can not recreate your situation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.