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 :
SERVER_WEB

no error is reporting from php.
thanks for all,

//*************** index.php : 
<?
error_reporting(E_ALL);
 
session_start();
include('includes/config.php');
//(...)
?>
 
//*************** config.php : 
define('SERVER_WEB',$_SERVER['SERVER_NAME']);
 
//*************** footer.php : 
<?=SERVER_WEB?>

Open in new window

LVL 5
beatboxradioAsked:
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 !
0
 
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.
0
 
beatboxradioAuthor Commented:
ok i've added new things...

into index.php :
error_reporting(E_ALL);
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 :
include(HTML_PATH.'footer.php');

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


0
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 <?=

0
 
beatboxradioAuthor Commented:
ok, i change again my things.

really strange...
//************ index.php
<?php 
error_reporting(E_ALL);
define('TEST','TTESTSETSETSETSET');
echo TEST;
 
//******** HTML_PATH works here, value is html/
include(HTML_PATH.'footer.php');
 
?>
 
//**************** footer.php
<?php echo TEST; ?>
 
 
//********** value of TEST show in index.php
/** TTESTSETSETSETSET
//********** value of TEST show in footer.php
/** TEST

Open in new window

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

http://php.net/manual/en/ini.core.php#ini.short-open-tag

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.

http://php.net/constants

You can use the defined() function to check if a constant is definied:

http://php.net/manual/en/function.defined.php
0
 
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.

thx






0
 
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 :
define('TEST', 'TTESTSETSETSETSET' );

0
 
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.

http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

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

include($_SERVER['DOCUMENT_ROOT'].'/beatboxradio_v6/html/footer.php'); 

Open in new window

0
 
beatboxradioAuthor Commented:
this is what i got :

5.2.5
allow_url_fopen=on
allow_url_include=on

thx for your new way to include !
0
 
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.
0
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.