0

Hi guys i have been trying to redirect a user back after login but it aint working i tried header it gave header already sent, tried php not working, tried javascript also not working ALSO TRIED USING REFERER also not wotrking. ANY HELP WOULD BE FINE. THis is my code:

<?php
if (isset($_POST['button']))
{
$userEntry = $_POST['pword']; // password user entered in form
$email=$_POST['Email'];  //email from form

$get_c= "SELECT * FROM `customers` WHERE Email='$email' AND     

pword='$userEntry'";

$run_c = mysqli_query ($con, $get_c);

$row_c = mysqli_fetch_array($run_c);

$c_id = $row_c['pword'] & $row_c['Email'] & $row_c['first_name'] &      
$row_c['Last_name'];

$_SESSION['fname']= $row_c['first_name']; 
$_SESSION['lname']=$row_c['Last_name']; 
$_SESSION['email']=$row_c['Email']; 

if ($userEntry == $row_c['pword']  & $email == $row_c['Email'] )
{
   echo"<script>alert('You have been logged in !')</script>";
  //Line for the redirect code to previous page before login i tried   
  doing    cleaned cause it did not work//

 } 
else
{
echo"<script>alert('Invalid email or password!')</script>";
echo"<script>window.open('login.php','_self')</script>";
}
}



THE FORM
          <form action="login.php" method="post" id="referrer">

                <span>Email Address</span>
                <input type="text" name="Email"> 

                <span>Password</span>
                <input type="password" name="pword"> 
                <div class="word-in">
                    <a class="forgot" href="http://www.drodx.com   

                  /forgotpassword.php">Forgot Your Password?</a>
                     <input type="submit" value="Login" name="button"  >
                </div>
            </form>

1 Answers1

0

I take it by, "redirect a user back after login" you mean to the page they where on before heading to the login page... if so then I'd suggest something like this:

<script>
function goBack() {
    window.history.go(-1);
}
</script>

The function above takes the user back one step in the window/tab's history.

Code tweak:

if ($userEntry == $row_c['pword']  & $email == $row_c['Email'] )
{
   echo"<script>alert('You have been logged in !');goBack()</script>";

or

if ($userEntry == $row_c['pword']  & $email == $row_c['Email'] )
{
   echo"<script>alert('You have been logged in !'); window.history.go(-1) </script>";