2015-03-08 108 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