-3

on a webpage view-source:http://cordbloodcenter.com/en/Corporate/Cord-blood.alej.html I just wrote a short PHP code but when I check source code, the PHP code font is green -> it change to a comment.

the PHP code is:

<?php
$myfile = fopen("units.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("units.txt"));
fclose($myfile);
?>

Why my PHP get changed to a comment? Thanks for help, -Luxqs

Luxqs
  • 53
  • 10

2 Answers2

2

the file extension .html is not parsed by the PHP interpreter. You can do the simple thing, and change the file extension to .php or make PHP parse .html files.

Go to the PHP ini file. At the end you will find this:

AddType application/x-httpd-php .php

change it to:

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

and a restart will activate it. If you use Apache it would be this command:

httpd -k restart

This is quite straightforward. Personally I prefer to keep the .html and .htm extension and hide the fact that I am using PHP. Why give away more information than needed? (not that obfuscation is a good way to implement security, but it cannot hurt). I also don't need to make an artificial distinction between pure html files and php file.

The downside is that all html files will go through the PHP parser, and this will be a tiny extra load on your server.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • Thanks, I dont have access, is there any other way? – Luxqs Dec 16 '14 at 09:41
  • 1
    There are a lot of answers on StackOverflow. For instance: http://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files You should be able to use a `.htaccess` file, simply upload it with FTP as any other file. – KIKO Software Dec 16 '14 at 09:43
1

You need to rename the file to file with .php extention! and then make sure you are opening it via a web server so that the php code gets compiled!

M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76