I'm trying to use include () function in my php script. But I just don't know what is the right way or professional way to do this.
Should I use environmental variables like $DOCUMENT_ROOT, $SERVER_NAME, $HTTP_HOST ?
How to use this environmental variable with the include() function ?
Is this alright ?
I'm not sure I understand your question entirely, but I just point to the file locally, like include("file.inc"), or include("../file.inc"), or include("directory/file.inc")
I tried what you did... but it give me error when I try to include the file from a external directory.
Anyway, I tried that
The path for an include in PHP is just like the source for an image. If the file to include is in the same directory as the calling file, it will be include("file.inc").
If the file to include is one directory higher, as in...
then the include would look like include("../file.inc"). The "../" tells PHP to look one directory or level higher than the file that wants the include.
Or, if the file to include is in a directory one level lower, as in
you would want include("includes/file.inc").
Hope you're getting all this. If I haven't confused you enough, here's a good one. If the PHP file and the file to include are each in seperate directories, like this...
then you would use include("../includes/file.inc"), which tells PHP to back up one level, then to look in the specified directory.
Anyway, I hope in something I said you can find something useful.
I tried to use relative path like
include("../phpdir/file1.php"); it give me errors.
My setup is like this:-
then in this file1.php, I have this line
<img src="images/pic2.jpg" width="720" height="80" border="0">
This file1.php is working file if I include this in
with this line
but if I want to include this file1.php in
with this line
it give me error regarding the include path and also the pic2.jpg is not displaying.
now, when I changed the inlcude to this
<img src="http://<? $SERVER_NAME/phpdir/images/pic2.jpg";?>" width="720" height="80" border="0">
It's working fine without error. So, do you know why is this happenning ?
I haven't a clue as to why your troubles are happening. Sounds very strange to me. I'll have to leave it to someone with more experience to answer this one.
It look strange to me either... Anyway I have solved my problem with the above method..
Just curious why this is happening.