我怎么能使用php die函数来仅停止加载某些div呢?我知道它可能不会和die完全一样,但是我怎么能只停止加载特定的div呢?所以我不想让learn "col“和"col”加载,而是让div id条加载。另外,如何使if语句中的H2标记不应用于else语句中的表?
<html>
<body>
<div id="header">
<div id="site">
<h1><a href="#">site</a></h1>
</div>
<div id="menuholder">
<ul id="menu">
<li><a href="index.html">Home</a></li>
<li class="active"><a href="about.php">about application</a></li>
<li><a href="#">register</a></li>
<li><a href="#">contact</a></li>
</ul>
</div>
</div>
<div id="teaser">
<div class="wrap">
<div id="image"></div>
<div class="box">
<?php
session_start ();
if (isset($_SESSION['username']))
echo "<h2>Welcome, ".$_SESSION['username']."!</h2>";
else
die("You must be logged in to view this page.
Register to gain access to learn more about the application.
<form action='login.php' method='POST'>
<table>
<tr><td>Username: </td><td><input type='text' name='username'/></td><td>Password: </td> <td> <input type='password' name='password'/></td> <td><input type='submit' name='submit' value='Login'/></td></tr>
</table>
</form>
");
?>
<p>Information about the application would go here</p>
</div>
</div>
</div>
<div id="bar">
<div class="wrap">
</div>
</div>
<div class="wrap">
<div class="col">
<h3>Learn <span class="red">More</span></h3>
<p>More info </p>
</div>
<div class="col">
<h3>User <span class="red">Statistics</span></h3>
<p>More info</p>
</div>
<div class="col last">
<h3>About <span class="red">Phapsy</span></h3>
<p>More info</p>
</div>
</div>
<div id="footer">
<p class="right">Contact: </p>
</div>发布于 2012-05-09 06:28:01
你不能。die()指示PHP停止进一步的处理。
然而,这是可行的:
<?php
session_start ();
if (isset($_SESSION['username'])) {
echo "<h2>Welcome, ".$_SESSION['username']."!</h2>";
$auth = true;
} else {
$auth = false; // Show the following HTML
?>
You must be logged in to view this page.
Register to gain access to learn more about the application.
<form action='login.php' method='POST'>
<table>
<tr><td>Username: </td><td><input type='text' name='username'/></td><td>Password: </td> <td> <input type='password' name='password'/></td> <td><input type='submit' name='submit' value='Login'/></td></tr>
</table>
</form>
<?php } // End ?>然后在别处..。
<?php if ( $auth == true ) { // Display this HTML only if authenticated ?>
<div class="col last">
<h3>About <span class="red">Phapsy</span></h3>
<p>More info</p>
</div>
<?php } // End ?>发布于 2012-05-09 06:27:59
在else部件中,只需使用echo()和exit显示您想要显示的任何文本。你不需要die()。
发布于 2012-05-09 06:29:19
使用if块:
<?php if($stuff): ?>
<div></div>
<?php endif; ?>"die“是一个句号;有办法拦截它,但不是方便的方法。在略有不同的情况下,"return“可能会执行所需的操作(因为它只退出当前函数或文件)。
https://stackoverflow.com/questions/10507437
复制相似问题