Authorization problem

The problem is that the code only checks the login from one page, but I need it to check the login from another page.
In general, how to make this code work

   $res_login = mysql_query( 'SELECT * FROM `datacenter` WHERE `login` = "'.mysql_real_escape_string($_POST['login']).'"' );
     $res_login1 = mysql_query( 'SELECT * FROM `datacenter` WHERE `login` = "'.mysql_real_escape_string($_SESSION['login']).'"' );
    if (mysql_num_rows($res_login) != 1 or mysql_num_rows($res_login1) != 1){
echo '<script>location.replace("nologin.php");</script>'; exit;
}
   else {.....
..........

Answer 1

Firstly, if you need all the information about the user, it is much more expedient to write all the information directly into the session during authorization and not disturb the database for nothing.

i.e. while checking authorization, do something like this:

session_start(); // -   :)
//      
if( !empty($_POST['login']) && !empty($_POST['password']) ) {
   //     
   //         
   //    md5 hash
   // -  ,   - 
   $login = '"' . mysql_real_escape_string($_POST['login']) . '"';
   $password = '"' . md5($_POST['password']) . '"';
   //     - 
   $userData = mysql_fetch_assoc(
       mysql_query('SELECT * FROM your_users_table WHERE login=' . $login .
               ' AND password=' . $passsoword
       )
   );
   //      -         
   // ..   
   if( $userData ) { //     
       //        
       foreach($userData as $key => $value) {
            $_SESSION[$key] = $value;
       }
       //    ...
   }
   else {
        //     ...
   }
}

It’s like a variant, so to speak, an attempt to read minds…

If you still need it exactly as you wrote, then just at the beginning of any script

session_start();
//    
if(!empty($_SESSION['login'])) {  //   
   $userData = mysql_fetch_assoc(
       mysql_query('SELECT * FROM your_users_table WHERE login=' . $_SESSION['login']
       )
   );
   foreach($userData as $key => $value) {
        $_SESSION[$key] = $value;
   }
}

I think in any case something will do, if I understand the question correctly, otherwise they are all kind of blurry 🙂