我在页面中嵌入PHP代码,为什么会直接在页面显示PHP源码啊,而不是解释处理后???
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
$file="textdata.txt";
if(isset($_POST["sub"])){
$message=$_POST["username"]."<|>".$_POST["title"]."<|>".$_POST["mess"]."<||>";
writeMessage($file,$message);
}
if(file_exists($file)){
readMess($file);
}
function writeMessage($file,$message){
$file_handle=fopen($file,"a");
if(flock($file_handle,LOCK_EX)){
fwrite($file_handle,$message);
flock($file_handle,LOCK_UN);
}else{
echo"不能锁定文件";
}
fclose($file_handle);
}
function readMess($file){
$file_handle=fopen($file,"r");
flock($file_handle,LOCK_SH);
$message="";
while(!feof($file_handle)) {
$massage.=fread($file_handle,2048);
}
$date=explode("<||>",$massage);
foreach($date as $line){
list($username,$title,$mess)=explode("<|>",$line);
if($username!=""&&$title!=""&&$mess!="")
echo $username.date("H-i-s",time())."说".$title.$mess."<br>";
}
flock($file_handle,LOCK_UN);
fclose($file_handle);
}
?>
<form action="" method="post" name="form">
用户名:<input type="text" name="username" size=10><br>
标题:<input type="text" name="title" size=30><br>
<textarea name="mess" rows=4 cols=38>请在这里留言</textarea><br>
<input type="submit" name="sub" value="提交">
</form>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
$file="textdata.txt";
if(isset($_POST["sub"])){
$message=$_POST["username"]."<|>".$_POST["title"]."<|>".$_POST["mess"]."<||>";
writeMessage($file,$message);
}
if(file_exists($file)){
readMess($file);
}
function writeMessage($file,$message){
$file_handle=fopen($file,"a");
if(flock($file_handle,LOCK_EX)){
fwrite($file_handle,$message);
flock($file_handle,LOCK_UN);
}else{
echo"不能锁定文件";
}
fclose($file_handle);
}
function readMess($file){
$file_handle=fopen($file,"r");
flock($file_handle,LOCK_SH);
$message="";
while(!feof($file_handle)) {
$massage.=fread($file_handle,2048);
}
$date=explode("<||>",$massage);
foreach($date as $line){
list($username,$title,$mess)=explode("<|>",$line);
if($username!=""&&$title!=""&&$mess!="")
echo $username.date("H-i-s",time())."说".$title.$mess."<br>";
}
flock($file_handle,LOCK_UN);
fclose($file_handle);
}
?>
<form action="" method="post" name="form">
用户名:<input type="text" name="username" size=10><br>
标题:<input type="text" name="title" size=30><br>
<textarea name="mess" rows=4 cols=38>请在这里留言</textarea><br>
<input type="submit" name="sub" value="提交">
</form>
</body>
</html> 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询