问题一
如何使 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
这将告诉用户我不想要的表单的实际正确用户名。
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/