问题
I have a file, manage.php, which contains php code, as depicted below.
Other files are working fine on the same PC and same server (I use WAMP). And the code is working correctly interacting with MySQL databases for a login mechanism on another page...
For some reason the code is not rendered in either FF or Chrome. In chrome, as you can see, the code gets commented out by html comment blocks and nothing prints or is read, etc. I did not write the code like that in my text editor.
I am frustrated. Any ideas?
http://captainscall.site11.com/temp_stuff/why-php.PNG
Here is the full script for manage.php:
<?php
/*
/admin/index.php
admin area for Neos Massage
Made by Douglas Franz, freelance PHP/MySQL/HTML/CSS/JS/jQuery-ist.
*/
session_start();
include('models/auth.php');
include('includes/database.php');
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Neos Massage Admin Area</title>
<script type="text/javascript" src="js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>
<div id="admin_header">
<img src="../images/header-background-restored-flower-no-color.png" style="vertical-align: top;"/>
<span><b>Admin Area</b><br /><?php if (isset($_SESSION['uName'])) { echo $_SESSION['uName']; } ?></span>
<div id="border">
<img src="../images/border.png" width="100%" height="20"/>
</div>
</div>
<div id="admin_content">
<h1 style="color: #402d11;">Neos Massage - Manage</h1>
<hr />
<a href="index.php?logout">logout</a>
<br />
<?php var_dump($_SESSION); echo "this is a test"; ?>
<?php print "this is a test"; ?>
</div>
</body>
</html>
回答1:
If what you are saying is true, that other *.php
files run without a problem, my assumption would be that the encoding you are saving the file in is causing the problem.
<!--?php
<- What Chrome is changing the PHP tag to make me think the encoding of the document is incorrect.
Try saving the file as a new document, or copy and pasting the code into a new document and saving it as a new file. I would bet that fixes your issue.
回答2:
Wow. Okay, so to diagnose it I copied the code in the file and then deleted manage.php altogether.
I then created a new file using the Windows Explorer GUI (the 'normal' way) called manage.php and pasted the code.
Then it worked.
Before I had created manage.php with Windows PowerShell using
new-item -type file manage.php
I have had similar problems where the encoding of PowerShell is not UTF-8 but Big-Endian or something and it...simply put, messes with things. I suppose this is a rare problem but a good lesson in diagnosing problems.
Thanks guys.
回答3:
This is definitely not a browser issue: it's an environmental one. Something in WAMP is not set up to execute this page as a PHP script.
来源:https://stackoverflow.com/questions/15098940/php-code-not-being-rendered-in-browsers