Hello all,
i am new to PHP and I am trying to use the "include" function in an HTML page and can't get it to work. Basically I have a file called "test.php" that I have uploaded to my ISP. test.php just reads some text from a text file ( I have verified that my ISP supports PHP4). I then created an HTML file in which I placed this line and also uploaded....
<? include("test.php"); ?>
when I go to the HTML page from my browser I get nothing. No error messages or anything. However, if I create a link to the PHP file from the HTML page, it works; I can see the text outputed from the textfile. It also works if I access the test.php file directly (ie. http://www.mydomain.com/test.php). I have tried changing permissions and using an actual path ("/path/to/file.php"). WHat am I doing wrong? Could it be something related to my ISP? Any help would be appreciated.
Thanks,
Sevi27
HELP! Need help with "include" function
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Does your ISP support short tags (<? ?>)? Have you tried using long tags:
What do you get if you view the source of the page?
Mac
Code: Select all
<?php include 'test.php'; ?>Mac
well, that worked. instead of using the .html extension for my page, I changed it to .php. All my other html code works as well as the php include function. Is this the way it is supposed to work?? This is the first I've heard of doing it this way, but then again I am very new to PHP. Thank you.
Sevi27
Sevi27
It was not working before because, according to your server, the "include" function was not inside a ".php" file.
You had it inside a ".html" file, therefore the server did not execute the PHP code you had inserted, it just served up the ".html" file and probably treated the PHP code you had on there as plain text to just show on the page.
The ONLY way a typical web server will know whether or not to execute PHP code in a file is if the file has the correct extension (such as ".php").
There are ways to make it so that files with a ".html" extension get executed through the PHP module as well, but usually you need access to edit the "php.ini" or the apache configuration file. Also, although it probably will not cause any problems, it is slightly inefficient to parse/execute every single ".html" file through the PHP module whether or not it has PHP in it or not. I have done it on some sites though and the performance hit is negligible unless you have tons (TONS!) of traffic.
You had it inside a ".html" file, therefore the server did not execute the PHP code you had inserted, it just served up the ".html" file and probably treated the PHP code you had on there as plain text to just show on the page.
The ONLY way a typical web server will know whether or not to execute PHP code in a file is if the file has the correct extension (such as ".php").
There are ways to make it so that files with a ".html" extension get executed through the PHP module as well, but usually you need access to edit the "php.ini" or the apache configuration file. Also, although it probably will not cause any problems, it is slightly inefficient to parse/execute every single ".html" file through the PHP module whether or not it has PHP in it or not. I have done it on some sites though and the performance hit is negligible unless you have tons (TONS!) of traffic.