PHP代码在使用WAMP的浏览器中显示为注释 [英] PHP code displaying as comments in browser using WAMP

查看:114
本文介绍了PHP代码在使用WAMP的浏览器中显示为注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在标题中所说的,我的PHP代码在浏览器代码检查器中显示出来,就像它已被注释掉一样。
例如,

 <? 
include(assets / php / dbconn.inc.php);
$ conn = dbConnect();

$ sql =SELECT * FROM movies;
$ rs = $ conn->查询($ sql)或死(电影查询失败);
$ number_of_rows = $ rs-> num_rows;


while($ row = $ rs-> fetch_assoc()){
echo({$ row ['title']});
}
?>

在浏览器中显示为

 <! - ? 
include(assets / php / dbconn.inc.php);
$ conn = dbConnect();

$ sql =SELECT * FROM movies;
$ rs = $ conn --->

以及其他代码打印在网页上。



我正在我的本地机器上使用WAMP进行测试。任何想法,这些评论标记来自何处?

解决方案

从不<?在您的PHP代码中。总是使用长标签<?php ,只是因为<?可以被禁用(或未启用,可能取决于在 php.ini 中加上 short_open_tag 指令(这看起来像是你的罪魁祸首)。结果,PHP脚本不会被PHP解释器处理,并且通常会以纯文本的形式发送给访问者,从而暴露您的整个源代码(还包括数据库凭据等)。


As is says in the title, my PHP code is showing up in the browser code inspector like it is commented out. For example,

<?
include("assets/php/dbconn.inc.php");
$conn = dbConnect();

$sql = "SELECT * FROM movies";
$rs = $conn->query($sql) or die ("Movie query failed");
$number_of_rows = $rs->num_rows;


while($row = $rs->fetch_assoc()){
echo("{$row['title']}");
}
?>

displays in the browser as

<!--?
include("assets/php/dbconn.inc.php");
$conn = dbConnect();

$sql = "SELECT * FROM movies";
$rs = $conn--->

and the rest of the code prints on the webpage.

I am testing this using WAMP on my local machine. Any idea where these comment tags are coming from?

解决方案

Never use short open tag <? in your PHP code. Always use long tags <?php, simply because <? can be disabled (or not enabled, may depend on distro) in php.ini with short_open_tag directive (and this looks like your culprit). In result, PHP scripts are not processed by PHP interpreter and will usually end up sent to the visitor as plain text, exposing your whole source code (but also DB credentials etc).

这篇关于PHP代码在使用WAMP的浏览器中显示为注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆