weixin_58648225 2021-10-15 18:23 采纳率: 89.2%
浏览 95
已结题

请教一个纯php的立旗方法用来捏合html

看似不是很短,但其实想捏合的地方就几块儿,下面粘贴目前的代码情况

<?php
$word = new word();
if (isset($_GET["complete"]) && $_GET["complete"] ==1){

}

$not_header_content = true;
$header = array(
    'title' =>"标题"
);

if (isset($_GET["reghash"])){
    $reghash      = htmlspecialchars($_GET["reghash"], ENT_QUOTES);
    $email        = htmlspecialchars($_GET["email"], ENT_QUOTES);
    $user_id      = user::get_user_id_by_hash($reghash);

    
    $user = new user($user_id);
        if ($user->is_show_menu(MENU_ID_SALON)) {
            header("Location: ".get_url_top().'/home/salon/user_input.php?action=activate&email='.$email.'&reghash='.$reghash);
            exit;
        }
    user::activate($email, $reghash);
    $info = user::get_info_by_id($user_id);

    $corp_id_info = null;

    if ($info) {
        $corp_id_info = bhcs_db::getCorpIDInfoWithCorpID($info->corp_id);
    }

    if ($corp_id_info && $corp_id_info->corp_id_type == CORP_ID_TYPE_STUDENT) {
        if (ha_db::avaiable()) {
            $res = ha_db::regist($info, $corp_id_info);
            $i_ha_user_id = $res->ha_user_id;
        } else {
            $res = new stdClass;
            $res->err_msg = '';
            $res->warning_msg = '错误信息';
            $i_ha_user_id = -1;
        }
        if (!$res->err_msg){
            $res = bhcs_db::regist($email, $email, $corp_id_info->client_id, $corp_id_info->app_id, 1);//creator_id = 1
            $i_bh_user_id = $res->student_id;
        }
        if (!$res->err_msg){
            $info = new stdClass;
            $info->ha_user_id = $i_ha_user_id;
            $info->bh_user_id = $i_bh_user_id;
            $info->role = CORP_ID_TYPE_STUDENT;
            if ($corp_id_info->guest== 0){
                $info->available = USER_AVAILABLE_REGULAR;
            }
            if ($user_id >= 0){
                $ss = '';
                $ss .= '<div class="message_area">';
                $ss .= '    <h2>信息</h2>';
                $ss .= '    <p>信息</p>';
                $ss .= '</div>';
                $ss .= '<div class="text-center mt20 mb20"><a href="login.php" class="btn btn-primary btn-lg">文字</a></div>';
            } else {
                $ss = "<div class=\"alert alert-danger\">错误信息1</div>";
            }
        } else {
            $ss = '';
            $ss .= '<div class="alert alert-danger">';
            foreach ($res->err_msg as $s_msg){
                $ss .= '<li>'.$s_msg.'</li>';
            }
            $ss .= '</div>';
        }
    } 

        if ($user_id >= 0) {
            $ss = '';
            $ss .= '<div class="message_area">';
            $ss .= '    <h2>信息</h2>';
            $ss .= '    <p>信息<br>信息</p>';
            $ss .= '</div>';
            $ss .= '<div class="text-center mt20 mb20"><a href="login.php" class="btn btn-primary btn-lg">确定</a></div>';
        } else {
            $ss = "<div class=\"alert alert-danger\">错误信息</div>";
        }
    }
?>

    <?php include(get_user_header()); ?>


        <section id="fh5co-container" data-section="home" class="mt-30" data-stellar-background-ratio="0.5">
            <div class="container">
                <div class="text-wrap">
                    <div class="text-inner">
                        <div class="page-header">
                            <h1>完成</h1>
                        </div>
                        <?php echo $ss; ?>
                    </div>
                </div>
            </div>
        </section>

    <?php include(get_user_footer());
    exit;
}
?>

<?php

$email            = $_POST["email"];
$password         = htmlspecialchars($_POST["password"], ENT_QUOTES);
$corp_id          = isset($_POST["corp_id"]) ? htmlspecialchars($_POST["corp_id"], ENT_QUOTES) : null;
$application_type = $_POST["application_type"];
$client_id        = isset($_POST["client_id"]) ? $_POST["client_id"] : null;


$bErr_email_dup = False;
if (($email != "") && (user::checkemailDuplicate($email) >= 0)){
    $bErr_email_dup = True;
}


if (isset($_POST["corp_id"])) {
    if ($bErr_email_dup || empty($password) || empty($corp_id) || empty($email) ){
        exit;
    }

} else if (isset($_POST["client_id"])) {
    if ($bErr_email_dup || empty($password) || empty($email) || empty($client_id) ){
        exit;
    }
} else {
    if ($bErr_email_dup || empty($password) || empty($email) ){
        exit;
    }
}

$id = user::make_and_sendmail_for_activate($email, $password, $corp_id, $application_type, $client_id);

$user_id = check_auth_user();
if($user_id == -1) {
    $ss = '';
    $ss .= '<div class="message_area">';
    $ss .= '    <h2>信息  </h2>';
    $ss .= '    <p>信息<br>信息2</p>';
    $ss .= '</div>';
    $ss .= '<div class="domain">';
    $ss .= '    信息3<br>';
    $ss .= '    信息4';
    $ss .= '    <span>' . SUPPORT_DOMAIN . '</span><br>';
    $ss .= '    信息5。<br><br>';
    $ss .= '    <span><a href="mailto:' . SUPPORT_EMAIL . '"><img src="/images/email_white.png"></a></span>';
    $ss .= '</div>';

    //+===========================================================================+
    // LOGGING-USER-ACTION
    // >>>START>>>
    //+===========================================================================+

    $table = database::get_table_with_scheme(LOG_USER_ACTION_TABLE_NAME);
    $token = isset($_SESSION['log_user_token']) ? $_SESSION['log_user_token'] : '';
    $log_user_action = database::fetch_one("SELECT * FROM ${table} WHERE token_c = '${token}';");

    $update          = new stdClass();
    $update->email   = $email;
    $update->page2   = date('Y-m-d H:i:s');

    if ($log_user_action && isset($log_user_action->id)) {
        database::update_by_id_with_pdo(LOG_USER_ACTION_TABLE_NAME, $log_user_action->id, $update);
        }

    unset($_SESSION['log_user_token']);

    //+===========================================================================+
    // <<<END<<<
    //+===========================================================================+

?>

<?php include (get_user_header()); ?>

<section id="fh5co-container" data-section="home" class="mt-30" data-stellar-background-ratio="0.5">
    <div class="container">
        <div class="text-wrap">
            <div class="text-inner">
                <div class="page-header">
                    <h1>完成</h1>
                </div>
                <?php echo $ss; ?>
            </div>
        </div>
    </div>
</section>

<?php include (get_user_footer()); ?>

<?php
} else {
    header("Location: ".get_url_top());
}

?>

询问一个关于php和html的立旗输出不同信息的问题,
在这种情况下 如何利用flag=true 和 fiag=false,将所有的html只捏合到此页的下方
(} else {header("Location: ".get_url_top());}的上面
换句话说就是只保留一对include就能输出所有的在此页中的信息

感谢解答

  • 写回答

1条回答 默认 最新

  • 月小升2016 2021-10-18 10:32
    关注

    感觉楼主希望代码变得逻辑清楚些

    楼主的代码加上函数即可转移html部分的代码。

    这样在任意调用的地方调用即可

    举例子楼主一段含有参数$ss的html代码提取为函数html_out,移动到代码段最后。之前的地方调用函数
    改造的代码段

    <?php include (get_user_header()); ?>
     
    <section id="fh5co-container" data-section="home" class="mt-30" data-stellar-background-ratio="0.5">
        <div class="container">
            <div class="text-wrap">
                <div class="text-inner">
                    <div class="page-header">
                        <h1>完成</h1>
                    </div>
                    <?php echo $ss; ?>
                </div>
            </div>
        </div>
    </section>
     
    <?php include (get_user_footer()); ?>
    
    
    

    将html代码改为函数调用

    <?php include (get_user_header()); ?>
    
    <?php html_out($ss); ?>
    
    <?php include (get_user_footer()); ?>
    

    移动到最后的html代码

    <?php
    function html_out($ss){
        echo '<section id="fh5co-container" data-section="home" class="mt-30" data-stellar-background-ratio="0.5">
        <div class="container">
            <div class="text-wrap">
                <div class="text-inner">
                    <div class="page-header">
                        <h1>完成</h1>
                    </div>
                    <?php echo $ss; ?>
                </div>
            </div>
        </div>
    </section>';
    
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月26日
  • 已采纳回答 10月18日
  • 修改了问题 10月15日
  • 修改了问题 10月15日
  • 展开全部

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测