我这里有login.php和home.php的代码 我想知道如何将欢迎信息发送到我的home.php,例如在我成功登录后,我将被重定向到主页,并且会有一个欢迎消息,如欢迎,然后用户名......用户可以看到PDO。 .can有些身体帮我这个.. 这是我的inde.php,login.php和home.php的代码
的index.php
<?php
session_start();
?>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul style="padding:0; color:red;">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<form action="reg.php" method="POST">
Username<br>
<input type="text" name="uname" /><br>
Password<br>
<input type="password" name="pword" /><br>
<input type="submit" value="Login" />
</form>
的login.php
<?php
session_start();
$errmsg_arr = array();
$errflag = false;
// configuration
$dbhost = "localhost";
$dbname = "pdo_ret";
$dbuser = "root";
$dbpass = "";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$user = $_POST['uname'];
$password = $_POST['pword'];
if($user == '') {
$errmsg_arr[] = 'You must enter your Username';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'You must enter your Password';
$errflag = true;
}
// query
$result = $conn->prepare("SELECT * FROM users WHERE username= :hjhjhjh AND password= :asas");
$result->bindParam(':hjhjhjh', $user);
$result->bindParam(':asas', $password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
if($rows > 0) {
header("location: home.php");
}
else{
$errmsg_arr[] = 'Username and Password are not found';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
?>
home.php
<div style="text-align:center;margin-top:50px;font-family:arial;font-size:20px;">
Congrats!<br>
You've Benn Successfully Entered<br>
In The<br>
System<br>
</div>
答案 0 :(得分:1)
只需在致电header("location: home.php");
$_SESSION['welcome_msg'] = "WELCOME " . $user; //
然后,在home.php中,start_session()
然后将$_SESSION['welcome_msg']
回显到您想要的位置。
如果要在欢迎消息中添加中断,可以随时在消息字符串中添加<br />
。
基本上,你对你的错误消息做了同样的事情。所以我猜你已经知道了。
编辑:
home.php
<?php
session_start();
?>
<div>
<p>
<?php echo $_SESSION['welcome_msg']; ?>
</p>
</div>