简体   繁体   English

PHP模具功能

[英]PHP die function

How could i use a php die function to only stop certain divs from loading? 我如何使用php die功能仅停止加载某些div? I understand it probably wouldnt be the exact same as die, but how could i stop only specific divs from loading? 我了解它可能与die完全不一样,但是我如何才能停止仅加载特定的div? So i want the learn "col" and "col last" not to load, but for the div id bar to load. 因此,我想学习的“ col”和“ col last”不是要加载的,而是要加载div id栏。 Also, how to i make it so the H2 tag in the if statement does not apply to the table in the else statement? 另外,如何使它在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>

You can't. 你不能 die() indicates to PHP to stop processing any further. die()向PHP指示停止进一步处理。

This, however, would work: 但是,这将起作用:

<?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 ?>

And then elsewhere... 然后在其他地方

<?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 ?>

In the else part just display whatever text you want to display using echo() and exit . else部分中,只需使用echo()显示想要显示的任何文本,然后exit You don't need to die() . 您不需要die()

Use an if block: 使用if块:

<?php if($stuff): ?>
    <div></div>
<?php endif; ?>

"die" is a full stop; “死”是一个句号; there are ways to intercept it, but not convenient ways. 有多种方法可以拦截它,但没有便捷的方法。 In a slightly different situation, "return" might do what you need (since it exits only the current function or file). 在稍微不同的情况下,“返回”可能会执行您需要的操作(因为它仅退出当前函数或文件)。

"So i want the learn "col" and "col last" not to load". “所以我不希望学习“ col”和“ col last”不加载”。 Highlight those lines with your mouse. 用鼠标突出显示这些行。 Hit the delete key :) 点击删除键:)

If you don't want them to display, use an if else statement. 如果您不希望它们显示,请使用if else语句。 It will look at the if part first, if it's true, it's executes the code, if it's false, it will move to the else statement and try that. 它将首先查看if部分,如果为true,则执行代码,如果为false,将移至else语句并尝试。

Please don't die! 请不要死! Don't abandon hope -- there's always an alternative. 不要放弃希望-总是有其他选择。

Try outputting your markup from within conditional statements. 尝试从条件语句中输出标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM