我在PHP文件中遇到意外的$ end问题。以下是错误发生的代码:
<style type="text/css">h2 { margin-bottom: 2px; }
.chomepage { border: 1px solid #888888;padding: 1px 2px; }
.conn-error { color: #FF0000; font-size: 15px; font-family: Courier New; }</style>
<?php $homepage = $_USER['homepage'];
if (isset($_GET['connection']) === false) { ?>
<h2>Manually change homepage</h2>
<form method="get">
<table><tr>
<td><input type="text" maxlength="15" size="15" value="<?=$_USER['homepage']?>" name="chomepage" class="chomepage2"></td>
<td><?php echo $tab; ?></td>
<td><input type="submit" value="Change homepage" class="zuris-button-round"></td>
<td style="width:100%;text-align:right;"><a href="?connection=<?=$homepage?>"><img src="/themayu/zuris/resources/icons/home.png"></a></td>
</tr></table>
</form>
<?php if (isset($_GET['chomepage'])) { ?><span class="chomepage"><?php $chomepage = sethome($_GET['chomepage']); if ($chomepage['status'] === true) {
echo "Your homepage has been changed to {$_GET['chomepage']}"; } else {
echo "Your homepage was not changed! Please try again"; }; }; ?>
</span><br /><?="\n"?>
<br /><h2>Connect to a server</h2>
<form method="get">
<table><tr>
<td><input type="text" maxlength="15" size="15" value="<?=$_USER['homepage']?>" name="connection"></td>
<td><?php echo $tab; ?></td>
<td><input type="submit" value="Connect to server" class="zuris-button-round"></td>
</tr></table>
</form>
<?php } elseif (isset($_GET['connection']) === true && isset($_GET['login']) === false) {
$connect = $_GET['connection'];
$player_rowcount = mysql_num_rows(mysql_query("SELECT * FROM `zuris` WHERE `ip` = '$connect'"));
$player_server_rowcount = mysql_num_rows(mysql_query("SELECT * FROM `player-servers` WHERE `ip` = '$connect'"));
$npc_rowcount = mysql_num_rows(mysql_query("SELECT * FROM `zuris-npc` WHERE `ip` = '$connect'"));
if ($player_rowcount > '0') { if ($connect != $_USER['ip']) { $logfile_id = mysql_result(mysql_query("SELECT `player_id` FROM `zuris` WHERE `ip` = '$connect'"), 0);
$logs = mysql_result(mysql_query("SELECT `logfile` FROM `zuris-player-logs` WHERE `logfile_id` = $logfile_id"), 0);
$session = rand(0000000000000000, 9999999999999999);
$logs = "[" . date('d-m-Y H:i:s') . "] Connection from [{$_USER['ip']}] with session ID [{$session}]\n" . $logs;
mysql_query("UPDATE `zuris-player-logs` SET `logfile` = '$logs' WHERE `logfile_id` = $logfile_id"); ?>
<?=$logs;
} else { echo "<script>window.location.assign('/themayu/zuris/connect.php?connection=127.0.0.1')</script>"; }; ?>
<center>
<table><tr>
<td>You were able to connect to the machine at <?=$connect?></td>
<td><?=$tab?></td>
<td><a href="?connection=<?=$connect?>&login=true"><button>Log in</button></a></td>
</tr></table>
</center>
<?php } else if ($player_server_rowcount > '0') { ?>
<center>
<table><tr>
<td>You were able to connect to the machine at <?=$connect?></td>
<td><?=$tab?></td>
<td><a href="?connection=<?=$connect?>&login=true"><button>Log in</button></a></td>
</tr></table>
</center>
<?php } else if ($npc_rowcount > '0') { $npc_info = mysql_fetch_assoc(mysql_query("SELECT * FROM `zuris-npc` WHERE `ip` = '$connect'"));
$npc_info['npc_description_line'] = str_replace("\n", "<br />", $npc_info['npc_description_line']);
$npc_info['npc_description_text'] = str_replace("\n", "<br />", $npc_info['npc_description_text']);
if ($npc_info['type'] === 'ftp') { $npc_info['npc_description_text'] = str_replace("(password)", "\"" . $npc_info['npc_password'] . "\"", $npc_info['npc_description_text']); }; ?>
<center id="browser-header">
<table style="width:100%"><tr>
<td style="width:60%;text-align:left;"><?php if ($_GET['connection'] != '127.0.0.1') { echo "You were able to connect to the machine at {$connect}";
} else { echo "You have connected to your computer at {$_USER['ip']}"; }; echo $tab; ?><a href="?connection=<?=$connect?>&login=true"><button>Log in</button></a></td>
<td style="width:40%;text-align:right;"><a href="?connection=<?=$homepage?>"><img src="/themayu/zuris/resources/icons/home.png"></a></td>
</tr></table>
</center>
<div id="server-info" style="overflow:auto;">
<div style="border-bottom:1px solid #888888;padding-bottom:1px;">
<form method="get">
<input type="text" name="connection" value="<?php if ($connect != '127.0.0.1') { echo $connect; } else { echo $_USER['ip']; }; ?>" class="url-bar">
<input type="submit" class="zuris-button-round load-url" value="Go">
</form>
</div>
<h2 class="remote-ip">Remote IP: <?php if ($_GET['connection'] != '127.0.0.1') { echo $connect; } else { echo $_USER['ip']; }; ?></h2>
<div id="server-text">
<p class="npc-description-line"><?=$npc_info['npc_description_line']?></p>
<p class="npc-description-text"><?=$npc_info['npc_description_text']?></p>
</div>
</div>
<div id="browser-footer">
<table style="width:100%;"><tr>
<td style="width:50%;"><?php if ($connect != '127.0.0.1') { echo $npc_info['npc_name']; } else { $lastchar = substr($_USER['username'], -1);
if ($lastchar != 's') { $string = '\'s'; } else { $string = '\''; }; echo $_USER['username'] . $string . " personal computer"; }; ?></td>
<?php if ($connect != '127.0.0.1' && $connect !== $_USER['homepage']) { ?>
<td style="width:50%;text-align:right;padding-right:10px;"><a href="?connection=<?=$connect?>&sethome">Set as homepage</a></td>
<?php }; ?>
</tr></table>
</div>
<?php } else { ?>
<center id="browser-header">
<table style="width:100%"><tr>
<td style="width:60%;text-align:left;">You were unable to connect to the server at <?=$connect?></td>
<td style="width:40%;text-align:right;"><a href="?connection=<?=$homepage?>"><img src="/themayu/zuris/resources/icons/home.png"></a></td>
</tr></table>
</center>
<div id="server-info" style="overflow:auto;">
<div style="border-bottom:1px solid #888888;padding-bottom:1px;">
<form method="get">
<input type="text" name="connection" value="<?=$connect?>" class="url-bar">
<input type="submit" class="zuris-button-round load-url" value="Go">
</form>
</div>
<h2 class="remote-ip">Remote IP: [NO CONNECTION]</h2>
<div id="server-text">
<p class="conn-error">The request to connect to <?=$connect?> failed</p>
</div>
</div>
<div id="browser-footer">
<table style="width:100%;"><tr>
<td style="width:50%;">Connection failed</td>
</tr></table>
</div>
<?php }; ?>
意外的$ end发生在代码的底部,<?php }; ?>
。这已经困扰了我一段时间,因为它适用于上面粘贴的代码块上方的行(这只是一个编辑过的副本和从它上面的代码块粘贴)
我已经尝试将其设置回echo '<p class="conn-error">The request to connect to ' . $connect . ' failed</p>';
,这非常有效。我也尝试了一种与外部div不同的方法,其内容与PHP一致回应。这导致了同样的错误。
变量$ connect和$ homepage正在写入用户输入的数据,$ connect由URL中的$ _GET [&#39; connection&#39;]写入,$ homepage通过$ _USER写入[ &#39;主页&#39]。对于这个问题,$ connect是&#39; 1.2.2.1&#39;和$ homepage是&#39; 1.1.1.1&#39;。
任何人都可以帮我吗?
编辑:已解决:我忘记了第二次};
关闭if (isset($_GET['connection']) === false) {
代码块{({1}})
我可以将此问题关闭为太本地化吗?
答案 0 :(得分:1)
如果这是整个PHP源代码集,那么问题是您使用的} else {
块打开了与之前的if语句不匹配的问题。例如,如果您将} else {
更改为if ( TRUE ) {
,则错误消失。
答案 1 :(得分:1)
我自己设法解决了这个问题。问题是我在};
?>
感谢您试图协助我 - Zuris