我将登录页面编码如下
<!DOCTYPE html5>
<html>
<head>
<? if (isset($_REQUEST['page1_submit'])) {
if ($_REQUEST['pword'] == "meatball") { ?>
<center><h2>You entered the correct password on the first try!</h2></center>
<? } else { ?>
<center><h2>Wrong Password! Try again.
<form method="POST" action="password.php">
Password: <input type="password" NAME="pword" /><br /><br />
<input type="submit" name="page2_submit" value="SUBMIT" />
<input type="reset" value="RESET" /><br />
</form>
</h2></center>
<? } ?>
<? } elseif (isset($_REQUEST['page2_submit'])) {
if ($_REQUEST['pword'] == "meatball") { ?>
<center><h2>You entered the correct password! But it took you two tries.</h2></center>
<? } else { ?>
<center><h2>Wrong Password Again! This was your second try.
<form method="POST" action="password.php">
Password: <input type = "password" name="pword" /><br /><br />
<input type="submit" name="page3_submit" value="SUBMIT" />
<input type="reset" value="RESET" /><br />
</form>
</h2></center>
<? } ?>
<? } elseif (isset($_REQUEST['page3_submit'])) {
if ($_REQUEST['pword'] == "meatball") { ?>
<center><h2>You entered the correct password! But it took you three tries.</h2></center>
<? } else { ?>
<center><h2>Wrong Password Again! You're out of luck.</h2></center>
<? } ?>
<? } else { ?>
<!-- This is the first pass for the user – page 1 -->
<center><h2>Please enter your password to access this site!<br />
<form method="POST" action="password.php">
Password: <input type="password" name="pword"><br /><br />
<input type="submit" name="page1_submit" value="SUBMIT" />
<input type="reset" value="RESET" /><br />
</form>
</h2></center>
<? } ?>
</body>
</html>
当我运行这个php时,一切都出现在同一页面上,而密码功能没有正常工作。
我甚至遵循了我们的教授提供的指南,但找不到任何明确的解决方案..
答案 0 :(得分:-1)
在PHP中,某些时候php.ini
设置为不允许短代码。
<?
是<?PHP
的缩写,如果您的服务器未设置为读取<?
,那么它将看起来像它一样。尝试将<?PHP
添加到所有<?
短代码。
如果服务器无法读取php的开始和结束,那么它将一起运行它们。
EX:
<?PHP
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<?PHP if (isset($_REQUEST['page1_submit'])) {
if ($_REQUEST['pword'] == "meatball") { ?>
<center><h2>You entered the correct password on the first try!</h2></center>
<?PHP } else { ?>
<center><h2>Wrong Password! Try again.
<form method="POST" action="password.php">
Password: <input type="password" NAME="pword" /><br /><br />
<input type="submit" name="page2_submit" value="SUBMIT" />
<input type="reset" value="RESET" /><br />
</form>
</h2></center>
<?PHP } ?>
请注意所有<?PHP
代码启动
请不要这样做,这是可怕的,你的导师需要关于清洁代码的一些教训