php - 如何将两种 CSS 类型添加到嵌入式 HTML 回显命令中并执行表单验证技术?

标签 php html css

问题一

如何使 echo html 段落加粗?这是我在下面尝试的 'text-align:center,font-weight: bold'

 echo "<div style='text-align:center,font-weight: bold'><p>Hello ". $_SESSION['username entered']."please enter the correct username or password for this login page.</p></div>";

 echo "<div style='text-align:center'><p>Hi, you left the form feilds blank, please your username/password.</p></div>";

问题二

当用户在我的表单中输入诸如“circle”之类的用户名时,我如何才能获取用户输入的随机用户名并将其显示在代码行 echo "<div style='text-align:center,font-weight: bold'><p>Hello ". $_SESSION['username entered']."please enter the correct username or password for this login page.</p></div>"; 中?如果我使用变量 username这将告诉用户我不想要的表单的实际正确用户名。

see how if I use "username" it will tell the user what the actual script user is? I want the original username they entered to be displayed for example, if I type in "hjhjhj" as the username where it says "test1" I want that random user to be displayed there please

PHP

    <?php
   session_start();

   //Selectional statement
   if ($_SERVER['REQUEST_METHOD'] === 'POST') {
       $user = $_POST["username"];
       $pass = $_POST["password"];
       //login aspect
       if($user != "" || $pass != ""){
           if($user=="test1"&&$pass=="test1"){
               $_SESSION['login'] = "OK";
               $_SESSION['username'] = $user;
               $_SESSION['password'] = $pass;

               header('Location: protected.php');    //Links with protected php file

           }else{  //If this codition is met output the below
               $_SESSION['login'] = "";
               echo "<div style='text-align:center,font-weight: bold'><p>Hello ". $_SESSION['username entered']."please enter the correct username or password for this login page.</p></div>";

           }
       }else{
         $_SESSION['login'] = "";
         echo "<div style='text-align:center'><p>Hi, you left the form feilds blank, please your username/password.</p></div>";
       }
   }
   ?>

HTML

         <!-- Form Input Part -->
         <form class="text-center" method="post">
            <div class="form-group w-50 mx-auto">
               <!-- First Name input section -->
               <label for="username">USERNAME:</label>
               <input id="username" class="form-control" type="text" maxlength="15" name="username" placeholder="Input your username.">
            </div>
            <div class="form-group w-50 mx-auto">
               <!-- Last Name input section -->
               <label for="password">PASSWORD:</label>
               <input type="password" class="form-control" type="text" maxlength="15" name="password" placeholder="Input your password.">
            </div>
            <!-- Form Button Submission -->
            <button type="submit" class="btn btn-dark">
            Login
            <i class="fas fa-sign-in-alt"></i>
            </button>
         </form>
      </div>

提前感谢您的帮助:)

最佳答案

问题一:

正如 Phix 在评论中所建议的那样,只需将您的内联样式更改为

text-align:center;font-weight: bold

使用分号代替逗号。

问题2:

这取决于你想要多少随机数,但如果它不重要,改变

$_SESSION['输入用户名'] 到以下之一:

  • substr(md5(time()),0,7)

  • substr(md5(rand(0, 3000)),0,7)

  • substr(base64_encode(openssl_random_pseudo_bytes(40)),0,7)

  • "用户".rand(0, 99999)

例如

echo "<div style='text-align:center,font-weight: bold'><p>Hello ". "User".rand(0, 99999).", please enter the correct username or password for this login page.</p></div>";

关于php - 如何将两种 CSS 类型添加到嵌入式 HTML 回显命令中并执行表单验证技术?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54484704/

相关文章:

javascript - 在javascript中自动跳转,这可能吗?

jquery - 标签链接系统

javascript - 如何根据视口(viewport)大小调整 Div 高度?

css - 如何在使用 azure blob 存储时解析 css 文件中的背景图像 url

php - 如何从字符串中删除这个多余的字符?

php - 这是什么数据,能转成JSON吗

php - 如何在 PHP 中动态调用类方法?

php - 终端中的退格键和 UTF8 编码

javascript - 链接悬停时jQuery淡入图像

jquery - Bootstrap 进度条动画使用 50% CPU