Adding PHP to HTML

Lavish

New member
Mar 18, 2008
110
1
0
Space.
Basic question I know... but I'm having issues after all the advice I've read... so...

I've tried implementing some PHP scripts I found online onto my landing pages - eg GEO display, date display etc.

I have the .php files, and I've tried passing them into the HTML files with some command (I forgot it now though :)) and I've also tried copying and pasting the code between the files.

Would appreciate some help.

Thanks.
 


If you are including php code into HTML files, put this in .htaccess:

AddType application/x-httpd-php .html .htm
 
If you are including php code into HTML files, put this in .htaccess:

AddType application/x-httpd-php .html .htm

Did this...

File tries to save automatically to the desktop... so I did it... opened it up... came back with this output:

OFFER EXPIRES: '; echo date('D M jS',$now); echo ' 11:59 PM'; ?>

The plot thickens...
 
You are trying to add PHP to an HTML file, which can't be done by default.

If changing the HTML files to PHP files is an option, that is the best option (meaning changing YourFile.html to YourFile.php). If you do this, your PHP will execute correctly.

If changing the filetypes is not an option, do what Houdas said. You will need to setup a .htaccess file to tell your server that .html files should process PHP code.

Check out these links for more info:

Run PHP from HTML - .html as .php - Execute PHP in .html

What is .htaccess? - Apache .htaccess Guide, Tutorials & Examples
 
This may seem pretty obvious, but make sure that your web server is actually set up to serve PHP scripts too... i.e., mod_php for apache. If it isn't, fix that first and then follow the rest of the instructions. You can find out by putting a simple file called test.php in your docroot containing "<?php phpinfo();" (without the quotes). If you hit it at /test.php and get a bunch of php information, you're good.
 
Did this...

File tries to save automatically to the desktop... so I did it... opened it up... came back with this output:

OFFER EXPIRES: '; echo date('D M jS',$now); echo ' 11:59 PM'; ?>

The plot thickens...

Let me guess your using a hosting provider such as GoDaddy and this was the first edit you've ever made to a .htaccess file? If correct or if you've never had a .htaccess file on your server before, after you update it sometimes it can take an hour or hour and a half before it updates on shared hosting account.

So if the .htaccess file is new on a shared server, after you update it, the changes won't take effect for an hour to hour and a half.

This isn't the case with all shared hosting accounts but with GoDaddy it is.