根据登录的人显示不同的链接

时间:2015-10-18 17:25:51

标签: html session if-statement navigation

我试图根据登录的人创建一些更改的链接,例如当用户登录时,登录更改以注销,刚开始制作if语句但他们似乎无法识别会议。谁能看到问题?原谅糟糕的布局,一直在玩。

的index.html

<!DOCTYPE html>
<html lang="en">
<head>
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="skeleton.css" />
        <link rel="stylesheet" type="text/css" href="normalize.css" />
  <!-- Basic Page Needs
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta charset="utf-8">
  <title>Assignment1</title>
  <meta name="description" content="">
  <meta name="author" content="">

  <!-- Mobile Specific Metas
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- FONT
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">

  <!-- CSS
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/skeleton.css">

  <!-- Favicon
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link rel="icon" type="image/png" href="images/favicon.png">

</head>
<body>

  <!-- Primary Page Layout
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->

  <?php
      if (isset($_SESSION['userlogged']))
      {


      ?>
     <div class="container">
     <div class="row">

      <center><h4>Basic Requirements</h4>
        <pre>        
      <a href="loginform.php" title="back to home">Logout</a>                     <a href="registrationform.php" title="back to home">Registration</a>                     <a href="contactus.php" title="back to home">Contact</a>                     <a href="searchform.php" title="back to home">Search</a>
        </pre>
    </div>
    </center>
  </div>
  <?php
      }
      else if (isset($_SESSION['adminlogged']))
      {

      }
      else
      {


  ?>
  <div class="container">
    <div class="row">

        <center><h4>Basic Requirements</h4>
        <pre>        
      <a href="loginform.php" title="back to home">Logout</a>                     <a href="registrationform.php" title="back to home">Registration</a>                     <a href="contactus.php" title="back to home">Contact</a>                     <a href="searchform.php" title="back to home">Search</a>
        </pre>
    </div>
    </center>
  </div>
  <?php
}
?>
<!-- End Document
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>

Loginsubmit.php

<?php
session_start();
?>
<font face="ClearSans-Thin">
<font color="lightgray">

<?php

include 'connection.php';
include 'loginform.php';

?>
<center>
<?php
if (isset($_POST['submit'])) 
    {

    $user = $_POST['username'];
    $pass = $_POST['password'];
    //Counts up how many matches there are in the database
    $query = "SELECT COUNT(*) AS cnt FROM users WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";
    $result = mysqli_query($connection, $query);
    $row = mysqli_fetch_assoc($result);

    /*$queryadmin = "SELECT COUNT(*) AS cnt FROM admin WHERE Username ='" . mysqli_real_escape_string($connection, $user) . "'AND Password='" . mysqli_real_escape_string($connection, $pass). "'";*/
    /*$resultadmin = mysqli_query($connection, $queryadmin);*/
    /*$rowadmin = mysqli_fetch_assoc($resultadmin);*/
    //If count is more than 0, log user in.
    if ($row["cnt"] > 0) 
    {
        $_SESSION["userlogged"] =  $user;
        echo "Logged in - Press the home button to return to the homepage";

    } 

    else if ($rowadmin["cnt"] > 0 )
        {
            $_SESSION["adminlogged"] = $user;
            echo "Logged in - Press the home button to return to the homepage";
        }
    else 
    {
        echo 'Not a valid login';
    }
}
?>

1 个答案:

答案 0 :(得分:0)

你的索引页面需要session_start();读取会话变量

            session_start();
            echo $_SESSION['userlogged'];