First of all, 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 to disturb the database in vain.
those. during the authorization check, you 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 { // код если пользователь ввел фигню... } }
This is an option, so to speak, an attempt to read the thoughts ...
If it is nevertheless necessary 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 understood the question correctly, otherwise they are all blurry for you :)