duandange7480 2011-09-08 21:36
浏览 41
已采纳

如何在成功登录Php后将此值回显到html

    <div class="content clearfix">
        <div class="left">
        <!--info-->

        </div>


    <?php

        if(!$_SESSION['id']):

        ?>

        <div class="left">
            <!-- Login Form -->
            <form class="clearfix" action="" method="post">
                <h2>Login</h2>

            <?php

                    if($_SESSION['msg']['login-err'])
                    {
                        echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
                        unset($_SESSION['msg']['login-err']);
                    }
                ?>

                <input class="field" type="text" name="username" id="username" value="User" size="23" onFocus="clearText(this)" />
                <input class="field" type="password" name="password" id="password" value="Pass" size="23" onFocus="clearText(this)" />
                <label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> &nbsp;Remember me</label>
            <div class="clear"></div>
                <input type="submit" name="submit" value="Login" class="bt_login" />
            </form>
        </div>
        <div class="left right">            
            <!-- Register Form -->

            <form action="" method="post">
                <h2>Sign Up!</h2>       
            <?php echo $id; ?>
            <?php

                    if($_SESSION['msg']['reg-err'])
                    {
                        echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
                        unset($_SESSION['msg']['reg-err']);
                    }

                    if($_SESSION['msg']['reg-success'])
                    {
                        echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
                        echo $_SESSION['id'];
                        unset($_SESSION['msg']['reg-success']);
                    }
                ?>

I basically want to output the version of the $_SESSION['id']; into html upon submission so that it can be grabbed from the page as a user navigates the site. So, if a user were to go to index2.php and logged in successfully, their ID (the PK for their username and pass combo) would be outputted to HTML so the code could grab that if say they go to prof.php next, that session var ID from $_SESSION['id']; could be grabbed by the page and used on prof.php if a user were to submit the form on prof.php

Can someone please help me be able to reuse this ID over and over as pages are navigated?

Thanks

  • 写回答

1条回答 默认 最新

  • du8442 2011-09-08 21:46
    关注

    It sounds to me like you want the id variable to be accessible across all of the pages a user visits.

    That is exactly what session is designed to do. You don't want to be writing the value to the page, since unless you put it in a form, and resubmit the form, the server side will never receive it again.

    Check out this reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题