2017-02-12 12 views
-2

ログイン後も同じページにリダイレクトしたいが、のような条件が必要な場合、ページはダッシュボードにリダイレクトされる。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']; 

そして、私は$_SESSIONでURLを取得することができるように、私は、example.phpで同じコードを使用していました。あなたのindex.phpログインフォームから

+0

HTMLコードを使用すると、mysqlのAPIを混合している – NoLiver92

+0

クライアントに送信されていない場合は、ヘッダーを使用することができます –

+0

も**このコードは実際の環境では使用しません。それは全く危険です。 –

答えて

0

<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); 

            } 
               ?> 
+0

thnx fr hlp。隠しフィールドwht私はhv login.phpに渡す? – nitul

+0

そして、私は値を渡してくれました。私はその値をdashboard.phpにリダイレクトしました。さらに、 "fromindex"という値をlogin.phpページの "fromindex11"に手動でchngedしました。 btはdashboard.phpにリダイレクトします – nitul

+0

$ _SESSION = mysqli_fetch_array($ verify_result、MYSQLI_ASSOC)の後に使用した条件を使用します。インデックスページのユーザーからのユーザーログインがdashboard.phpにリダイレクトされ、他のページからユーザーがログインすると、exemple.phpページにリダイレクトされます。 –

関連する問題