0

I'm already logged in!

then it's still appear

But when i'm go to info user page, it's alright!

I really known where problem is! But I cant do anything to fix it! Before learning php and html myself, I'm a java coder! I'm already searching google a lot of times, but I cant find IF/ELSE statement. Here the code:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Kai2552 index</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
    /* Remove the navbar's default margin-bottom and rounded borders */ 
    .navbar {
      margin-bottom: 0;
      border-radius: 0;
    }
    
    /* Set height of the grid so .sidenav can be 100% (adjust as needed) */
    .row.content {height: 800px}
    
    /* Set gray background color and 100% height */
    .sidenav {
      padding-top: </br>px;
      background-color: #f1f1f1;
      height: 100%;
    }
    
    /* Set black background color, white text and some padding */
    footer {
      background-color: #555;
      color: white;
      padding: 15px;
    }
    
    /* On small screens, set height to 'auto' for sidenav and grid */
    @media screen and (max-width: 767px) {
      .sidenav {
        height: auto;
        padding: 15px;
      }
      .row.content {height:auto;} 
    }
  </style>
</head>
<body>
<?php
      require_once("connection.php");


// If result matched $username and $password, table row must be 1 row
  $check=0;
      if(isset($_POST['submit'])){
        $username = "";
        $password = "";

        $username = $_POST['username'];
        $password = md5($_POST['password']);

        $message = "";
        $query = "SELECT * FROM THANHVIEN WHERE username = '$username' AND password = '$password'";
        $resultObj = $connection->query($query);
        if($resultObj->num_rows > 0)
        {
          while($singleRowFromQuery = $resultObj->fetch_assoc())
          {
            // print_r($singleRowFromQuery);
            $message = "Login success";

            session_start();
            $_SESSION['id'] = $singleRowFromQuery[id];
            $_SESSION['username'] = $username; // store username
            $_SESSION['password'] = $password; // store password
            $_SESSION['email'] = $singleRowFromQuery[email];
            $_SESSION['fullname'] = $singleRowFromQuery[fullname];
            $_SESSION['birthday'] = $singleRowFromQuery[birthday];
            $_SESSION['gender'] = $singleRowFromQuery[gender];
    $_SESSION['loggedin'] = true;
   $check=1;
 
            header("Location:index.php");
            exit;
          }
        }
        else{
            $message = "Login failed! please try again..";
        }
      }
     ?>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="#">Group Web</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="index.php">Home</a></li>
        
  <button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#myModal">About us</button>

  <!-- Modal -->
  <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

   <!-- Modal content-->
   <div class="modal-content">
     <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">asjdjsad</h4>
     </div>
     <div class="modal-body">
    <p>sakdjsad</p>
    <p>nonoaskdjaskd</p>
     </div>
     <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
     </div>
   </div>

    </div>
  </div>
        <li><a href="#">Projects</a></li>
        <button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#myModal1">Contact</button>

  <!-- Modal -->
  <div id="myModal1" class="modal fade" role="dialog">
    <div class="modal-dialog">

   <!-- Modal content-->
   <div class="modal-content">
     <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Phạm Tấn Anh Khoa</h4>
     </div>
     <div class="modal-body">
    <p>K21CMUTPM2</p>
    <p>ID: 2121118118</p>
    <p>Fb: <a href="nolink"><button type="button" class="btn btn-default btn-xs">Click</button></a></p>
     </div>
     <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
     </div>
   </div>

    </div>
  </div>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <div class="dropdown">
  <button class="btn btn-default btn-lg dropdown-toggle" type="button" data-toggle="dropdown">
  

  
  <?php 
  session_start();
       if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
           echo 'welcome : '.$_SESSION['username']."";
       }
       else{
           echo '‿✿⁀‿✿⁀ʟoԍιɴ oʀ sιԍɴ ιɴ➻❥➻❥';
       }
       ?>

  <span class="caret"></span></button>
  <ul class="dropdown-menu">
    <form method="post" class="panel panel-body panel-default">
        <div class="form-group">
  
            <label for="username">Username: </label>
            <input type="text" name="username" class="form-control">
        </div>
        <div class="form-group">
            <label for="password">Password: </label>
            <input type="password" name="password" class="form-control">
        </div>
        <div class="form-group">
          <button type="submit" name="submit" class="btn btn-success">Login</button>
          <button type="reset" class="btn btn-default">Reset</button>
        </div>
      </form>
   <span class="text-muted">---Don't have an account?<br> <a href="register.php">---Create yours now</br></a></span>
  </ul>
</div>
      </ul>
    </div>
  </div>
</nav>
  
<div class="container-fluid text-center">    
  <div class="row content">
    <div class="col-sm-2 sidenav">
    
    </div>
    <div class="col-sm-8 text-left"> 
      <h1>Welcome to my test site</h1>
      <p>Hi i'm Khoa! This is the first website i designed myself. Thank to W3school.com for help me do it. I'm very glad despite of simple website. Here my love song, Fairy Town - Chen Yifa: </p>
   <audio controls>
  
  <source src="FairyTown-ChenYiFa-4692100.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
 </audio>
 <p>Lyrics:</p>
   <button data-toggle="collapse" data-target="#demo">Chinese Pinyin</button>

   <div id="demo" class="collapse">
   <br>Tīng shuō báixuě gōngzhǔ zài táopǎo </br>
<br>xiǎohóngmào zài dānxīn dà huī láng</br>
<br>tīng shuō fēng mào xǐhuan àilì sī</br>
<br>chǒuxiǎoyā huì biànchéng bái tiān'é</br>
<br>tīng shuō bǐde pān zǒng cháng bù dà</br>
<br>jiékè tā yǒu shùqín hé mófǎ</br>
<br>tīng shuō sēnlín li yǒu tángguǒ wū</br>
<br>huī gūniang diūle xīn'ài de bōlí xié</br>
<br>zhǐyǒu ruìzhì de héshuǐ zhīdào</br>
<br>báixuě shì yīnwèi tān wán pǎo chūle chéngbǎo</br>
<br>xiǎohóngmào yǒu jiàn yìzhì zìjǐ</br>
<br>biànchéng láng de dàhóng páo</br>
<br>zǒng yǒu yītiáo wān yán zài tónghuà zhèn li qīcǎi de hé</br>
<br>zhānrǎn mófǎ de guāizhāng qìxí</br>
<br>què yòu zài àilǐ qūzhé</br>
<br>chuānliúbùxī yáng qǐ shuǐhuā</br>
<br>yòu juàn rù yī lián shíguāng rùshuǐ</br>
<br>ràng suǒyǒu hěnjiǔ hěnjiǔ yǐqián</br>
<br>dōu zǒu dào xìngfú jiéjú de shíkè</br>
<br>tīng shuō shuì měirén bèi máicáng</br>
<br>xiǎo rényú zài tiàowàng jīn diàntáng</br>
<br>tīng shuō ābō luó biànchéng jīnwū</br>
<br>cǎoyuán yǒu bēnpǎo de jiànchǐhǔ</br>
<br>tīng shuō pǐ nuò cáo zǒng shuōzhe huǎng</br>
<br>zhūrú guài yǒngyǒu bǎoshí mǎn xiāng</br>
<br>tīng shuō xuányá yǒu kē chángshēng shù</br>
<br>hóng xiézi bùzhī píjuàn de zài tiàowǔ</br>
<br>zhǐyǒu ruìzhì de héshuǐ zhīdào</br>
<br>shuì měirén táobìle shēnghuó de jiān'áo</br>
<br>xiǎo rényú bǎ yángguāng mǒ chéng yǎnyǐng</br>
<br>tóu jìn pàomò de huáibào</br>
<br>zǒng yǒu yītiáo wān yán zài tónghuà zhèn li qīcǎi de hé</br>
<br>zhānrǎn mófǎ de guāizhāng qìxí</br>
<br>què yòu zài àilǐ qūzhé</br>
<br>chuānliúbùxī yáng qǐ shuǐhuā</br>
<br>yòu juàn rù yī lián shíguāng rùshuǐ</br>
<br>ràng suǒyǒu hěnjiǔ hěnjiǔ yǐqián</br>
<br>dōu zǒu dào xìngfú jiéjú de shíkè</br>
<br>zǒng yǒu yītiáo wān yán zài tónghuà zhèn li mènghuàn de hé</br>
<br>fēngéle lǐxiǎng fēngé xiànshí</br>
<br>yòu zài qiánfāng de shānkǒu huìhé</br>
<br>chuānliúbùxī yáng qǐ shuǐhuā yòu juàn rù yī lián shíguāng rùshuǐ</br>
<br>ràng suǒyǒu hěnjiǔ hěnjiǔ yǐqián</br>
<br>dōu zǒu dào xìngfú jiéjú de shíkè yòu mòshēng</br>
   </div>
   <button data-toggle="collapse" data-target="#demo1">Vietnamese</button>

   <div id="demo1" class="collapse">
   <br>Người ta nói Bạch Tuyết đã chạy trốn xa</br>
<br>Và cô bé khăn đỏ run sợ sói già</br>
<br>Rằng Hatter bấy lâu yêu thương  Alice</br>
<br>Chú vịt kia giờ đây bỗng hoá thiên nga</br>
<br>Peter Pan vẫn thế, chẳng vội lớn nhanh</br>
<br>Chàng Jack  đem đàn hạc cùng nhiều phép màu</br>
<br>Rừng sâu có một nhà chỉ toàn kẹo bánh</br>
<br>Chiếc giày đánh rơi quý giá của lọ lem mang theo</br>
<br>Chỉ dòng sông khôn ngoan mới hiểu mọi lý do</br>
<br>Nàng Bạch Tuyết ham chơi mới chạy trốn khỏi lâu đài</br>
<br>Vì cô bé mang chiếc áo nhuộm màu đỏ tươi</br>
<br>Giữ bản thân không hoá sói được</br>
<br>Vẫn đây một dòng sông uốn khúc chảy theo thị thành cổ tích hằng ngày</br>
<br>Chút không khí kỳ lạ bủa vây phép màu, với con sông xuyên ái tình ai</br>
<br>Đâu bọt nước tung lên toả sáng  trong không gian, cuốn theo thời gian tan dần</br>
<br>Mọi thứ đã rất lâu ngày xửa ngày xưa, tất cả đều kết thúc trong hạnh phúc bền lâu</br>
<br>Người đẹp ngủ quên vốn đã bị giấu đi</br>
<br>Nàng tiên cá ngẩn ngơ ngắm nhìn cung điện</br>
<br>Mặt trời kia có phải thần Apollo</br>
<br>Chú cọp mang tên răng kiếm chạy trên thảo nguyên</br>
<br>Phải chăng Pinocchio chỉ dối thôi</br>
<br>Rumpelstiltskin có rương đầy báu vật</br>
<br>Nơi vách đá vỗn dĩ có cây trường sinh</br>
<br>Chiếc giày nhún nhảy đỏ thắm chẳng biết lúc nghỉ ngơi</br>
<br>Chỉ dòng sông khôn ngoan mới hiểu mọi lý do</br>
<br>Người đẹp ngủ quên để lẩn tránh đi cuộc sống khổ đau</br>
<br>Nàng tiên cá mang nắng hoá thành những giấc mơ nào</br>
<br>Ước mong tan đi như bọt biển</br>
<br>Vẫn đây một dòng sông uốn khúc chảy theo thị thành cổ tích hằng ngày</br>
<br>Chút không khí kỳ lạ bủa vây phép màu, với con sông xuyên ái tình ai</br>
<br>Đâu bọt nước tung lên toả sáng  trong không gian, cuốn theo thời gian tan dần</br>
<br>Mọi thứ đã rất lâu ngày xửa ngày xưa, tất cả đều kết thúc trong hạnh phúc bền lâu</br>
<br>Vẫn đây một dòng sông uốn khúc chảy theo thị thành cổ tích hằng ngày</br>
<br>Rẽ hai lối riêng biệt hiện thực với mơ, để bên nhau dưới núi xây đắp tình ta</br>
<br>Đâu bọt nước tung lên toả sáng  trong không gian, cuốn theo thời gian tan dần</br>
<br>Mọi thứ đã rất lâu ngày xửa ngày xưa, tất cả đều kết thúc trong hạnh phúc bền lâu đầy xa lạ..</br>
   </div>
      <hr>
      <h3>My best beautiful girl...</h3>
     <p> <div class="row">
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/1.jpg">
        <img src="gakky/1.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/2.jpg">
        <img src="gakky/2.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/3.jpg">
        <img src="gakky/3.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
</div></p>
<p> <div class="row">
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/4.jpg">
        <img src="gakky/4.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/5.jpg">
        <img src="gakky/5.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
  <div class="col-md-4">
    <div class="thumbnail">
      <a href="gakky/6.jpg">
        <img src="gakky/6.jpg" alt="Gakky" style="width:100%">
        
      </a>
    </div>
  </div>
</div></p>
    </div>
    <div class="col-sm-2 sidenav">
      
    </div>
  </div>
</div>



</body>
</html>
AKBK
  • 45
  • 1
  • 9
  • 1
    Please dont __roll your own__ password hashing. PHP provides [`password_hash()`](http://php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://php.net/manual/en/function.password-verify.php) please use them. And here are some [good ideas about passwords](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) If you are using a PHP version prior to 5.5 [there is a compatibility pack available here](https://github.com/ircmaxell/password_compat) – RiggsFolly Sep 12 '17 at 12:27
  • If you are only expecting a single row from your query, why are you fetching the result in a while loop – RiggsFolly Sep 12 '17 at 12:28
  • You must start your session BEFORE outputting anything to the browser. Where you have your `session_start()` means it will not start a session, therefore the related tests will fail!!!!! – RiggsFolly Sep 12 '17 at 12:30
  • Get into the habit of looking at your PHP Error log – RiggsFolly Sep 12 '17 at 12:30
  • **Or Add** `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. – RiggsFolly Sep 12 '17 at 12:31
  • tks you! i want to login board cant appear when im already logged in! Instead of it, i expect another board i want! sorry for my bad english! Can you advise me some solutions? I can do the simple login board without dropdown toggle, but i dont want to do that! If i cant fix it, i will do the simple way !Tks you very much! – AKBK Sep 12 '17 at 12:36
  • Move your session start to above the ` ` line like this ` ` – RiggsFolly Sep 12 '17 at 12:38
  • yes, i got it! tks your advise – AKBK Sep 12 '17 at 12:44

0 Answers0