2015-03-08 77 views
-1

enter image description here在线登录表单PHP

enter image description here

所以我试图做我的web应用程序 它看起来像附照片的每一个网页的登录部分,但我在会议中遇到困难。

如果用户登录不显示FORM>显示下拉列表 但我总是得到下拉未经登记,

我想要一个简单的代码怎么把我会为我做的m confused 有没有简单的方法来指导我完成整个过程?由于

 <?php 

       /* 
       *Create db in mydb for users 
       *connect 
       *recieve from login forum >> check with db if exists 
       *start session > save the id of that user >> display the forum with details of his profile 
       */ 

       /* 
       if(isset($_POST["submit"])){ 
        $user= $_POST["username"]; 
        $pass= $_POST["password"]; 
        //$_SESSION["username"]=$user; 
        echo "username is clicked"; 
       }else{ 
        echo "nothing is clicked"; 
       } 
       */ 

       $signin=false; // checking the concept 
       $_SESSION["username"] =$signin; 
       if(isset($_SESSION["username"])){ #if the user is signed in 

        echo $_SESSION["username"]; 
        $query= "select * from users"; 
        $select= mysqli_query($connection, $query); 
        while ($row = mysqli_fetch_assoc($select)){ 
         $userid = $row["idusers"]; 
         $username=$row["username"]; 
         $password= $row["password"]; 

        } 
       ?> 
        <ul class="nav navbar-nav navbar-right"> 
        <li> 
         <a href="help.html">Help</a> 
        </li> 
        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $username;?><strong class="caret"></strong></a> 
         <ul class="dropdown-menu"> 
          <li> 
           <a href="profile.php?id=<?php echo "$userid";?>">Profile</a> 
          </li> 
          <li> 
           <a href="#">Contests</a> 
          </li> 

          <li class="divider"> 
          </li> 
          <li> 
           <a href="signout.php">SignOut</a> 
          </li> 
         </ul> 
        </li> 
       </ul> 
      </div><?php 
       }else{ 

        ?> 
         <form class="navbar-form navbar-right" method="post" role="search"> 
         <div class="form-group"> 
          <input type="text" class="form-control" name="username" placeholder="Username"> 
         </div> 
         <div class="form-group"> 
          <input type="password" class="form-control" name="password" placeholder="Password"> 
         </div> 
         <button type="submit" class="btn btn-default">Sign In</button> 
         </form> 


        <?php 

       } 

       ?> 

回答

0

假设你设置一个变量,当有人登录时,看着你使用我打赌$_SESSION

<?php 
    if (!empty($_SESSION['user_logged_in'])) { 
     echo " "; // HTML when the user is logged in 
    } else { 
     echo " "; // HTML when the user is logged out 
    } 
+0

但我使用所有在一个页面中的标签,我想将所有内容都包含在一个页面中 – 2015-03-08 21:30:40

+0

已经改变了使用'echo'而不是include的解决方案,只需在引号中插入要包含的HTML。 – redreddington 2015-03-08 22:41:53