Jump to content

[SOLVED] Constants Problem


Fadion

Recommended Posts

I am making a website for a client with a simple php/mysql custom cms. The problem i am facing is when using constants. They cant seem to work. Ex:

 

I have a config.php file where i put all the configuration constants

define('SITE_TITLE', 'My Webiste');

 

When echoing SITE_TITLE locally i get 'My Website' but on the shared host i just get 'SITE_TITLE' echoing. I can fix those by using variables but i would need to change a lot of code. Has anybody else faced this problem and if so how did u fix it?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/67660-solved-constants-problem/
Share on other sites

How are you echo'ing the constant? Make sure you don't wrap the constant in quotes eg:

echo 'SITE_TITLE';
// OR
echo "SITE_TITLE";

The constant has to be on its own eg:

echo SITE_TITLE;

 

Prehaps check to see if the constant SITE_TITLE is defined first before using it:

if (defined('SITE_TITLE')) {
    echo SITE_TITLE;
}
else
{
    echo "'SITE_TITLE' does not exist";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.