2014-06-22 43 views
-5

我有这样保存文件作为PHP和HTML

<!DOCTYPE html> 
<html> 
<head> 
<title>test</title> 
<?php 
include ('set/tags.html') 
?> 
<link href="/style.css" rel="stylesheet" type="text/css"> 
</head> 
<body> 
<div class="header" id="header"> 
<?php 
include ('set/header.php'); 
?> 
</div> 
<div class="menu"> 
<center> 
<?php 
include 'set/menu.php'; 
?> 
</center> 
</div> 
<div class="mainbody" id="body"> 
<center> 
<table border="0"> 
<tr> 
<td> 
<a href="numbers"><img src="img/number.png" onmouseout="this.src='img/number.png'" onmouseover="this.src='img/number2.png'"/></a> 
<br><center><font face="Trebuchet MS" size="4">Numbers</font></center></br> 
</td> 
<td> 
<a href="algebra"><img src="img/algebra.png" onmouseout="this.src='img/algebra.png'" onmouseover="this.src='img/algebra2.png'"/></a> 
<br><center><font face="Trebuchet MS" size="4">Algebra</font></center></br> 
</tr> 
</table> 
<?php 

$handle = fopen("counter.txt", "r"); 
if(!$handle){ 

echo "could not open the file" ; 

} 
else { 


    $counter = (int) fread($handle,20); 
    fclose ($handle); 
    $counter++; 
    echo "<strong> You're ". $counter . "<sup>th</sup> visitor</strong>"; 
$handle = fopen("counter.txt", "w"); 
fwrite($handle,$counter) ; 
fclose ($handle) ; 
    } 
?> 

</center> 
</div> 
<div class="footer"> 
<?php 
include 'set/footer.php'; 
?> 
</div> 
<div class="side" id="side"> 

<center> 
<?php 
include 'set/side.php'; 
?> 
</center> 
</div> 

</body> 
</html> 

代码,当我将它保存为index.php文件,一切正常。但是当我将它保存为index.html时,php部分不起作用!

是否有人知道问题是什么?

顺便说一句,我使用的iPage主机 ,当我使用000webhost的是,它工作时,我保存为HTML只有

+2

因此,当您将它保存为不是PHP的文件时,它不会被视为PHP?我想知道为什么??? –

+1

将其更改为.jpg并查看它的图片 –

+0

可能的重复[如何将PHP代码添加到.html文件?](http://stackoverflow.com/questions/11312316/how-do-i-add- php-code-to-html-files) –

回答

1

文件扩展名为.PHP(.php3和.phtml作为某些服务器上太)在默认情况下是作为php脚本执行的。如果你有权访问服务器配置,你可以设置服务器来执行.html文件作为脚本,但我不会推荐它(出于性能的原因)。更好地使用“标准方式”并命名带有.php扩展名的php脚本文件。

+0

php3 ??我真的不希望 –