2016-03-03 124 views
1

我如何隱藏這個 - 「<div class="show1">」當用戶沒有登錄,並且只有當用戶登錄時才顯示?隱藏並顯示div文件(登錄)

這是我的代碼--- >>>

<html><head> 
    <meta charset="utf-8"> 
    <title>100% | Register</title> 
    <link rel="stylesheet" type="text/css" href="main/home.css"/> 
    <link rel="stylesheet" type="text/css" href="main/register.css"/> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script></head><body><div id="container"> 
    <?php include 'header.php'; ?> 
    <br/><br/><div class="show1">TEXT</div><div class="show1">TEXT</div> 
    <div class="hidden1"><div class="right-login" id="container-login"><div id="palabi5px"> 
    <form method="post" class="formpost" id="nonono"> 
     <input type="text" class="username" name="username0" placeholder="Username" autocomplete="off"> 
     <input type="password" class="password" name="password0" placeholder="********">   
     <button type="submit" name="login" class="loging">Login</button> 
    </form> 
    --------------------------------- 
    <br/><br/> 
    Text!<br/><br/> 
    <br/> 
    --------------------------------- 
    <br/><br/></div></div></div> 
    <?php include 'saites.php'; ?></body></html> 

<?php 
session_start(); 
require('connect.php'); 
$username0 = @$_POST['username0']; 
$password0 = @$_POST['password0']; 

if(isset($_POST['login'])){ 
    if($username0 && $password0) { 
    $check = mysqli_query($connect," SELECT * FROM users WHERE username='".$username0."'"); 
    $rows = mysqli_num_rows($check); 

     if(mysqli_num_rows($check) != 0){ 
      while($row = mysqli_fetch_assoc($check)){ 
       $db_username0 = $row['username']; 
       $db_password0 = $row['password']; 
      } 
      if($username0 == $db_username0 && ($password0) == $db_password0){ 
       @$_SESSION["username"] = $username; 
       echo "<script type='text/javascript'> 
       $(document).ready(function(){  
        alert('page loaded'); // alert to confirm the page is loaded  
        $('.hidden1').hide(); //enter the class or id of the particular html element which you wish to hide. 
        $('.show1').show(); //SHOW 
       }); 
       </script>"; 
      }else{ 
       echo "<script>{ alert('Your pass id wrong.');}</script>"; 
      } 
     }else{ 
      echo "<script>{ alert('Couldn't find username.');}</script>"; 
     } 
    }else{ 
     echo "<script>{ alert('Please fill in all the fields.');}</script>"; 
    } 
} 
?> 
+0

使用會話ID,以檢查用戶是否登錄 – cheralathan

+0

我不是PHP的專家,但對我來說,它看起來像你有SQL注入攻擊的風險。 –

+1

請查看http://php.net/manual/en/security.database.sql-injection.php安全性更重要。 – cheralathan

回答

0
<div class="show1">TEXT</div><div class="show1">TEXT</div> 

替換下面的代碼

if(isset($_SESSION["username"])){ 
     echo '<div class="show1">TEXT</div><div class="show1">TEXT</div>'; 
    }