Use <?php ..... ?> , <?php echo $var; ?>, <?php $var="string"; ?> instead of the short open tags ( <? ....?>, <? echo $var; ?>, <?="string" ?>. Short open tags look more convenient but they only cause more problems.
Btw, short open tags will be done away with in PHP 6.
__________________
For professional Hosting and Web design.....
Well that didn't work. In fact, i originally had the long tags, but changed it to the short to see if it made any difference.
Any other ideas? From what I can see, the code looks ok.
Oh, this document is named as test.html
I take it it should be with a html suffix and not php, right?
I'm on win 7.
I did write a small script with just the php tags and called it test.php and ran that one and that worked ok.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
Thanks, it's working like this, but I would also like to know how to configure my server so that I can use both.
Does anyone know how to do this? I'm pretty sure it has to be in the .htaccess file but that file doesn't seem to let the server work when I manipulate that file. I'm not sure if it's because I'm using XAMPP and I'm supposed to put it in some other proxy file.
You can't, or more accurately you do not want to (I'm sure it could be done, but it would be very unwise). File protocol is a filesystem access protocol. If you chain it to webservices for preprocessing, than you will not be able to open files properly. IE: I can open any file on my machine by typing in file://path/to/file.txt, so the last thing I want is to have it intercepted by webservers for preprocessing.
Always access it through the http protocol or on the command line via php.exe execution.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Oh yeah, so what file do I need to change?
I read somewhere that it's like this
Code:
# Use PHP5 by default
AddHandler application/x-httpd-php5 .php
AddHandler application/x-httpd-php5 .html
But I just put it in the .htaccess file and that didn't work.
Which file do I have to put these lines in?
Dave.
This is what I have - notice the minor differences:
AddType application/x-httpd-php .html
Also as Redcoder says, drop the short tags. They were supposed to be a useful thing once but they're a pita as not all servers have them enabled - makes life hell when moving from one server to another. Additionally it also wreaks havoc with any .xml files you also have if .xml is configured to be run by php using the AddType in your .htaccess file.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
I fixed it. I found this off another forum in a google search.
I had to change this file in xampp
\xampp\apache\conf\extra\httpd-xampp.conf
from:
<FilesMatch "\.php$">
to:
<FilesMatch "\.(php|html)$">
So that's fixed. My second question would be, are there any dangers to doing this?
Or do we generally want to make web applications that will use the parsing of php in html files.
That fix means that your apache / php will now check every file across every directory. That'll grind it down a bit more and imagine what will happen on a live server with thousands of visitors..
As for the .html thing, yes there is a reason why we don't recommend it. .html is used for static pages that don't change. .php is used for dynamic pages. If you use .html for dynamic then the webserver has to check every .html page for dynamic content which given enough users and connections will grind it down. Thats why we have the .php extension so that you can choose and switch between resource intensive and non resource intensive.
It's also why it's recommended to use the .htaccess file instead of the main config file for some things because you casn specify different options for different folders. You've just with overkill lol.
If you really want to hide the use of php then just use folder names and index.php file names to mask it. EG:
/account/
/edit/
/update/
In each of those folders you have index.php but you never call or link to the php file, just the actual folder. The webserver will serve the index file by default.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.