引入用户名和密码后,登录表单脚本更改

时间:2015-06-01 09:55:24

标签: php mysql forms

我有这样的表格:

<div class="page3">
              <form id="indexform" action="index.php" method="post">
              <table class="datatable2"  style="padding:20;" >
              <tr>

                  <td><center>Username  </center><input type="text" name="name" value="" size="10" /></td>

              </tr>
              <tr>

                  <td><center>Password </center><input type="password" name="password" value="" size="10" /></td>
              </tr>
              <tr>
               <td colspan="2" class="datatable2" style="padding:55 0 0 38;">
                      <input type="submit" value="Log In" name="admsubmit" class="subbtn" style="background-image: url(imagini/autentificare.png);background-repeat:no-repeat;background-position:10 5;background-size:17px;"/></form>

                  </td>
                  <tr>
                  <td colspan="2" class="datatable2" style="padding:40 0 0 8;">
                      <form action="parola_uitata.php"> <input type="submit" align="right" value="Ai uitat parola?" class="subbtn" style="background-image: url(imagini/parola_uitata.png);background-position:11;background-repeat:no-repeat;background-size:17px;margin:-45 1;padding-left:30;" name="parola_uitata"></form>

                  </td>
              </tr>
</table>

             </div>

图片:

http://i.stack.imgur.com/4dvWP.png

我想知道如何在登录后隐藏,并且只在同一个div中显示如下:Hello ($_SESSION['user']) - 转到管理面板。如果有人能给我一些想法,那对我有帮助。

1 个答案:

答案 0 :(得分:0)

在您的标记周围包装if语句,并根据会话状态显示(如果他们已登录或未登录)

<div class="page3">
    <?php if(!isset($_SESSION['logged_in'])) : ?>
         <form id="indexform" action="index.php" method="post">
          <table class="datatable2"  style="padding:20;" >
             <tr>
                <td><center>Username</center><input type="text" name="name" value="" size="10" /></td>
            </tr>
            <tr>
                <td><center>Password </center><input type="password" name="password" value="" size="10" /></td>
            </tr>
            <tr>
               <td colspan="2" class="datatable2" style="padding:55 0 0 38;">
                          <input type="submit" value="Log In" name="admsubmit" class="subbtn" style="background-image: url(imagini/autentificare.png);background-repeat:no-repeat;background-position:10 5;background-size:17px;"/></form>

                      </td>
                      <tr>
                      <td colspan="2" class="datatable2" style="padding:40 0 0 8;">
                          <form action="parola_uitata.php"> <input type="submit" align="right" value="Ai uitat parola?" class="subbtn" style="background-image: url(imagini/parola_uitata.png);background-position:11;background-repeat:no-repeat;background-size:17px;margin:-45 1;padding-left:30;" name="parola_uitata">
                   </form>
               </td>
          </tr>
    </table>
    <?php else : ?>

    <-- User logged in, show control panel stuff !-->

    <?php endif; ?>
</div>