How to setup site-wide variables in php?

Most PHP sites should have a file (I call it a header) that you include on every single page of the site. If you put that first line of code in the header file, then include it like this on every page:

 include 'header.php';

you won't have to use the global keyword or anything, the second line of code you wrote should work.

Edit: Oh sorry, that won't work inside functions... now I see your problem.

Edit #2: Ok, take my original advice with the header, but use a define() rather than a variable. Those work inside functions after being included.


Sounds like the job of a constant. See the function define().


Do this define ('el','\n\<\br/>\n'); save it as el.php

then you can include any files you want to use, i.e

echo 'something'.el; // note I just add el at end of line or in front

Hope this help

NOTE please remove the '\' after < br since I had to put it in or it wont show br tag on the answer...

Tags:

Php