0

I need someone's expertise. Once the user is logged in.... I want them to be redirected to another php page if they attempt to go back to the login page. Right now my user can still login but also is able to go back to the login form.

<?php

if(isset($_POST['login'])){

session_start();

$password = $_POST['pass'];
$email = $_POST['email'];

$user_pass= md5($user_pass);

$check_user = "select * from userss where user_pass='$password' AND user_email='$email'";

$run = mysql_query($check_user);

if(mysql_num_rows($run)>0){

$_SESSION['email']=$email;

echo "<script>window.open('welcome.php','_self')</script>";
}
else {
echo "<script>alert('Email or password is incorrect!')</script>";
   }

}

?>
Marc Delisle
  • 8,879
  • 3
  • 29
  • 29
  • possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Isaac Bennetch Apr 29 '15 at 18:45

2 Answers2

0

This type of question has already been answered. See How to make a redirect in PHP?

You are already be checking the login status of your user prior to serving any page. Right?

if (logged_in){
  header("Location: http://example.com/myOtherPage.php");
  die();
}
Community
  • 1
  • 1
Jed
  • 1
  • 1
  • 4
    *This type of question has already been answered* Why do you then post an answer? You can vote for close as dupe/ write a comment/ flag it to get closed – Rizier123 Apr 28 '15 at 00:42
  • I'm new to the site... I know the answer was probably answered but since I'm a newb with coding, I thought maybe if I place my code down, I could get a better answer – Taavon Monroe Apr 28 '15 at 01:04
0

try this.

this processlogin.php write this code:

if(isset($_POST['login'])){
    session_start();
    $password = $_POST['pass'];
    $email = $_POST['email'];
    $user_pass= md5($user_pass); 
    $check_user = "select * from userss where user_pass='$password' AND user_email='$email'";
    $run = mysql_query($check_user);
    if(mysql_num_rows($run)>0){ 
        $_SESSION['email']=$email; 
        echo "<script>window.open('welcome.php','_self')</script>";
    } else { 
        echo "<script>alert('Email or password is incorrect!')</script>"; 
    } 
}

in login.php write this code:

    <?php 
if(session_start()){
       echo "<script>window.open('welcome.php','_self')</script>";
    }else{ ?>
       <form method='post' action='processlogin.php' class="form-signin">
           <h2 class="form-signin-heading">Login </h2>
           <label for="inputEmail" class="sr-only"></label>
           <input type="email" id="inputEmail" name="email" class="form-control" placeholder="Email address" required autofocus><br>
           <label for="inputPassword" class="sr-only"></label>
           <input type="password" id="inputPassword" name="pass" class="form-control" placeholder="Password" required><br/>
           <button type="submit">LOGIN</button>
       </form>
    <?php } ?>

hope this can help.

randawahyup
  • 389
  • 2
  • 5
  • 15