这个问题在这里已有答案:
我试图通过一个链接发送2个变量到我的PHP页面,我无法弄清楚我做错了什么。结果不对。我期待只显示值,而不是显示整个PHP代码。
感谢您提前帮助,下面是我的HTML,PHP和结果。
我的html页面名为“index.html”,我的php“default.php”
HTML:
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Information sänd via adressfältet och länkar</title>
<meta charset="UTF-8">
</head>
<body>
<a href="default.php?name=filip&gender=man">Link</a>
</body>
</html>
PHP:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
结果:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
有一些因素会影响第一个确认你的php模块是否正确配置到Apache并且它读取.php扩展名2你的文件实际上保存为.php如果你使用文本编辑器如记事本附加了.txt文件格式最后,除非您选择文件类型作为所有文件
我找到了这个问题thnx:PHP code is not being executed, instead code shows on the page
问题是:
确保使用http://localhost/file.php等网址通过网络服务器访问文件,而不是通过本地文件访问文件://localhost/www/file.php