如何在登录PHP后重定向到与用户名相同的页面
我想在登录后在同一页面上重定向,但我需要这样的条件:如果用户名和密码来自index.php,那么页面将重定向到dashboard.php,如何在登录PHP后重定向到与用户名相同的页面,php,Php,我想在登录后在同一页面上重定向,但我需要这样的条件:如果用户名和密码来自index.php,那么页面将重定向到dashboard.php,,否则它将在同一页面上重定向(example.php) login.php: <?php include ('include/connection.php'); if (isset($_POST['loginform'])) { session_start(); $email = trim(mysql_escape_string($_PO
,否则它将在同一页面上重定向(example.php)
login.php:
<?php
include ('include/connection.php');
if (isset($_POST['loginform'])) {
session_start();
$email = trim(mysql_escape_string($_POST['email']));
$passwords = trim(mysql_escape_string($_POST['pwd']));
$password = md5($passwords);
$verify_query = "SELECT * FROM end_user WHERE (email='$email' AND password='$password')";
verify_result = mysqli_query($con, $verify_query);
if(!$verify_result){
echo '<h2>Couldnot Process your request Please try to login after some time. </h2>';
}
if (@mysqli_num_rows($verify_result) == 1) {
$_SESSION = mysqli_fetch_array($verify_result, MYSQLI_ASSOC);
header("Location: dashboard.php");
}
else {
echo '<h2 style="color:#CC3300;">Incorrect Credentials, You need to register <a href="signup.php" style="font-size:20px;" class="btn btn-primary">Here</a></h2>';
}
mysqli_close($con);
}
?>
我在
example.php
中使用了相同的代码,因此我可以在$\u会话中从索引中获取URL
<input type="hidden" name="extrafield" value="fromindex">
然后
如果没有向客户端发送html,您可以使用header。您也在混合mysql API,并且不要在实时环境中使用此代码;这是完全不安全的。您的代码在很多级别上都失败得很惨。您也有一个非常糟糕的跟踪记录thnx fr ur hlp。在隐藏字段wht i hv to pass to login.php?中,我还传递值wht u hv sugst me,bt its nt wrkng,它的唯一重定向到dashboard.php,甚至我在login.php页面中手动将值“fromindex”更改为“fromindex11”。bt它唯一的重定向到dashboard.phpUse我在$\u SESSION=mysqli\u fetch\u array($verify\u result,mysqli\u ASSOC)之后使用的条件;如果用户从索引页面登录,用户将重定向到dashboard.php,如果用户从其他页面登录,他们将重定向到example.php页面。Thnx先生,其wrkng…逻辑是vry smple,bt i mk it complctd by myslf。曾经的agn thnx ji先生。。。。。。
<input type="hidden" name="extrafield" value="fromindex">
<?php
include ('include/connection.php');
if (isset($_POST['loginform'])) {
session_start();
$email = trim(mysql_escape_string($_POST['email']));
$passwords = trim(mysql_escape_string($_POST['pwd']));
$password = md5($passwords);
$verify_query = "SELECT * FROM end_user WHERE (email='$email' AND password='$password')";
$verify_result = mysqli_query($con, $verify_query);
if(!$verify_result){
?>
<?php
echo '<h2>Couldnot Process your request Please try to login after some time. </h2>';
}
if (@mysqli_num_rows($verify_result) == 1)
{
$_SESSION = mysqli_fetch_array($verify_result, MYSQLI_ASSOC);
if(isset($_POST['extrafield']) == 'fromindex'){
header("Location: dashboard.php");
} else {
header("Location: exmple.php");
}
}else
{
?>
<?php echo '<h2 style="color:#CC3300;">Incorrect Credentials, You need to register <a href="signup.php" style="font-size:20px;" class="btn btn-primary">Here</a> </h2>';
}
mysqli_close($con);
}
?>