PHP code displaying as comments in browser using WAMP [closed]

╄→гoц情女王★ 提交于 2020-01-04 08:22:34

问题


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?


回答1:


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).




回答2:


Posted on behalf of the OP:

SOLVED I was navigating to the file directly instead of through the localhost address. Rookie mistake.



来源:https://stackoverflow.com/questions/20434280/php-code-displaying-as-comments-in-browser-using-wamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!