All my pages are static HTML pages now. I have to modify every file if I want to change head or footer. I want to create a template file in php and I can call this php template file from each HTML file. where should I add the include() function? Do I need to start session first? I tried to add this <?php session_start(); include("black-panther-animal-template.php"); ?> inside the HTML body. It didn't work. I am complete new to php. Please give me some help.
I think your trying to use PHP in a HTML file, If you are using apache as web server you can use like this.
Add this to your .htaccess file. AddType application/x-httpd-php .php .html Code (markup): Then in the header php file. <?php $header ='INSERT_HTML_CODE_HERE'; echo $header; unset($header); ?> PHP: Then in the html file where the header should appear put. <?php include(headerfile.php); ?> HTML: There is more then one way to skin a cat, that is basic. It's not tested, but should work.
There are some error messages. I think it is caused by AddType application/x-httpd-php .php .html I had run .php and .html files separately without problems. I can create a page as a .php file and call the php template file inside the body like this: <?php include(template.php); ?> It works fine. But I don't want to change all files to .php files. In that case, I will lose all search engine index, backlinks, and bookmarks, etc. Any suggestions?
Putting the AddType application/x-httpd-php .php .html in .htaccess makes it so you do not have to change the names of your existing files. That will allow php to be parsed in html files. The only files with .php will be your new include files like template.php.
When I add: AddType application/x-httpd-php .php .html I get error message like this: The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Also what is the purpose of this piece of code for <?php $header ='INSERT_HTML_CODE_HERE'; echo $header; unset($header); ?> Just print out a string? I didn't add that. Hope that is not the reason for the error. Thanks a lot.
The error is not the php, but off hand, I don't know exactly why it would cause that. Ask your host if you can use that directive in the .htaccess file. BTW, this is for an apache server, I don't know if that works on windows servers. Yes, the php you show outputs a string, the html code for the template. In your html files where you want to be able to show say a header, you can use that. You create one php file, put a snippet of php in each html file, then then in the future, to change the header, you only edit one file.
My sites are on Apache server 1.3.37. If I remove that line: AddType application/x-httpd-php .php .html There is no error message. But the template is not imported. I guess when I save a file as template.php, it also include whole set of head, body, etc. If another HTML call this .php file, there is some conflict.