首页 > 解决方案 > PHP / ORACLE 获取当前登录用户的用户名

问题描述

我正在尝试获取当前登录用户的用户名,以便我可以做一些事情,例如在欢迎屏幕上显示用户名。我正在使用 php 将用户连接到 oracle11g 数据库。我收到错误 *注意:未定义变量:第 88 行 C:\xampp\htdocs\CamtelWork\eBusiness\index.php 中的 dbuser

注意:未定义的索引:在第 88 行的 C:\xampp\htdocs\CamtelWork\eBusiness\index.php* 我已经定义了我的变量,但我不知道应该如何解决这个问题/问题。

这是我的代码

登录.php

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                      // always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");                          // HTTP/1.0

session_start();
$uri = $_SERVER['PHP_SELF'] . "?" . SID;
if( isset($_POST['dbuser']) ) {
  $dbuser = $_POST['dbuser'];
}
if( isset($_POST['pass']) ) {
  $pass = $_POST['pass'];
}
?>

<title>Oracle in php database user login page</title>


<?php
// have username and password been passed from a form?
if ( isset($dbuser) && isset($pass) ) {
  // try to connect to Oracle with user and password supplied
        $conn = oci_connect($dbuser, $pass, 'localhost/orcl');


  if (!$conn) {
      $e = oci_error();
      echo htmlentities($e['message'], ENT_QUOTES);
    unset($dbuser); unset($pass);
  }
}

// username and password will be unset if they weren't passed,
//  or if they were wrong


if( !isset($dbuser) || !isset($pass) ) {
    // just print form asking for account details



echo "

<body>
  <div class=login-wrap>
  <div class=login-html>
    <input id=tab-1 type=radio name=tab class=sign-in checked><label for=tab-1 class=tab>Connection</label>
    <input id=tab-2 type=radio name=tabclass=sign-up><label for=tab-2 class=tab></label>
    <div class=login-form>


";


     echo "<form action=\"$uri\"  method=post style='max-width:500px;margin:auto; background-color:#c8c8c8;'>\n";

echo "<div style='display: -ms-flexbox; /* IE10 */
  display: flex;
  width: 100%;
  margin-bottom: 15px;'>";
echo "</div>";


    echo "</div>";



 echo "<input type=text name=dbuser class=input placeholder=Utilisateur style='width: 70%;
  padding: 10px;
  outline: none;
 border: 2px solid dodgerblue; position:absolute; top:200px; margin-left:-05px;'>\n";





echo "<div style='display: -ms-flexbox; /* IE10 */
  display: flex;
  width: 100%;
  margin-bottom: 15px;'>";


 /* style for username and pass IE10 */


  echo "<h4 style=' position:absolute; top:150px; margin-left:px;'>Utilisateur</h4>
 ";

  echo "<h4 style='position:absolute; top:250px; margin-left:px;'>Password:";



echo "</div>";



echo "<div>";


    echo " <h4 style=''><input type=password name=pass placeholder=Mot_de_Pass style='width: 70%;
  padding: 10px;
  outline: none;
 border: 2px solid dodgerblue; position:absolute; top:300px; margin-left:-05px;'>\n";
 echo "</div>";
    echo "<br><input type=submit name=login value=Login style='  background-color: dodgerblue;
  color: white;
  padding: 15px 20px;
  border: none;
  cursor: pointer;
  width: 80%;
  opacity: 0.9;  position:absolute; top:400px;'>\n";
    echo "</form>\n";
    exit;
}

欢迎页面

<?php

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                      // always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");

session_start();
$uri = $_SERVER['PHP_SELF'] . "?" . SID;
if( isset($_POST['dbuser']) ) {
  $dbuser = $_POST['dbuser'];
}
if( isset($_POST['pass']) ) {
  $pass = $_POST['pass'];
}
?>

<title>Oracle in PHP test page</title>


<?php
// have username and password been passed from a form?
if ( isset($dbuser) && isset($pass) ) {
  // try to connect to Oracle with user and password supplied
        $conn = oci_connect($dbuser, $pass, 'localhost/orcl');


  if (!$conn) {
      $e = oci_error();
      echo htmlentities($e['dbuser'], ENT_QUOTES);
    unset($dbuser); unset($pass);
  }
}

?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Welcome Page - Index</title>
  <meta content="" name="descriptison">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/favicon.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700|Raleway:300,400,400i,500,500i,700,800,900" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="assets/vendor/animate.css/animate.min.css" rel="stylesheet">
  <link href="assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <link href="assets/vendor/nivo-slider/css/nivo-slider.css" rel="stylesheet">
  <link href="assets/vendor/owl.carousel/assets/owl.carousel.min.css" rel="stylesheet">
  <link href="assets/vendor/venobox/venobox.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- =======================================================
  * Template Name: eBusiness - v2.0.0
  * Template URL: https://bootstrapmade.com/ebusiness-bootstrap-corporate-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>






<body data-spy="scroll" data-target="#navbar-example">

  <!-- ======= Header ======= -->
  <header id="header" class="fixed-top">
    <div class="container d-flex">

      <div class="logo mr-auto">
        <h1 class="text-light"><a href="index.html"><span>Welcome </span> <?php echo htmlentities($_GET["$dbuser"])."<br/>";?></a></h1>
        <!-- Uncomment below if you prefer to use an image logo -->
        <!-- <a href="index.html"><img src="assets/img/logo.png" alt="" class="img-fluid"></a>-->
      </div>

请问我该如何解决这个问题或者我应该如何编写我的代码?提前致谢!

标签: phpdatabaseoracleuser-controlsdisplay

解决方案


推荐阅读