如何在登录后用用户名重定向到同一页面PHP
我想在登录后重定向到同一页面,但我需要像if username and password come from index.php
这样的页面将重定向到dashboard.php,else it will redirect on the same page (exmple.php)
。如何在登录后用用户名重定向到同一页面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);
}
?>
的index.php:
session_start(); // starts the session
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
而且我用同样的代码在example.php
,这样我就可以在$_SESSION
得到URL。
从你的index.php登录表单传递一个隐藏字段一样
<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);
}
?>
thnx fr ur hlp。在隐藏的领域,我高压传递给login.php? – nitul
并且我还将这个值直接传递给它,它的nt wrkng,它唯一的重定向到dashboard.php,即使我在login.php页面中手动将值“fromindex”改为“fromindex11”。 bt其唯一重定向到dashboard.php – nitul
使用$ _SESSION = mysqli_fetch_array($ verify_result,MYSQLI_ASSOC)后使用的条件;如果用户从索引页面用户登录将被重定向到dashboard.php,并且如果用户从其他页面登录,他们将被重定向到exemple.php页面。 –
您可以使用头,如果没有HTML已发送到客户端 – NoLiver92
你的mysql混合的API也是 –
并且不要**在实时环境中使用此代码;这完全不安全。 –