我们通过php会话从数据库中调用id的人

时间:2019-07-19 15:02:17

标签: php

谁可以通过$ _SESSION从数据库获得“ id”。我的代码在下面给出,用于管理员登录页面。我需要在不同页面上而不是同一页面上的“ id”。

import jenkins.model.*
import java.util.logging.Logger

def logger = Logger.getLogger("")
def installed = false
def initialized = false
def plugins = ["git", "cloudbees-folder", "build-timeout"]

logger.info("" + plugins)
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
plugins.each {
  logger.info("Checking " + it)
  if (!pm.getPlugin(it)) {
    logger.info("Looking UpdateCenter for " + it)
    if (!initialized) {
      uc.updateAllSites()
      initialized = true
    }
    def plugin = uc.getPlugin(it)
    if (plugin) {
      logger.info("Installing " + it)
        def installFuture = plugin.deploy()
      while(!installFuture.isDone()) {
        logger.info("Waiting for plugin install: " + it)
        sleep(3000)
      }
      installed = true
    }
  }
}
if (installed) {
  logger.info("Plugins installed, initializing a restart!")
  instance.save()
  instance.restart()
}

1 个答案:

答案 0 :(得分:-1)

include 'db.php';   // create database connection

    if(isset($_POST['email']) && isset($_POST['password'])){
        $email = $_POST['email'];
        $password = $_POST['password'];
        $hashed_password = password_hash($password, PASSWORD_DEFAULT);

        $login_query = "SELECT * FROM admin WHERE email='$email' AND password='$hashed_password'";
        $result = mysqli_query($conn, $login_query);
        $num_rows = mysqli_num_rows($result);

  if($num_rows == 1){
    $data = mysqli_fetch_array($result);
    $current_password = $data['password'];

     if (password_verify($password, $current_password)) {
      //Password matches, so create the session

      $_SESSION["uid"]=$data["uid"];
      $_SESSION["uname"]=$data["uname"];
    header("Location: http://localhost/school/admin/dashbord.php");
     exit();
    }
   else
    {
        echo "The username or password do not match";
    }  
}

其他php页面:

<?php
session_start();

if(!isset($_SESSION["uname"])){
    header('Location:index.php');
    exit();
}

<?php echo $_SESSION["uid"]; ?>   // get database id on second page
                                     through session
?>