mam prośbę o sprawdzenie mojego kodu, wszystko jest ok po za tym że jeśli nic nie robię przez ok 20 min to wylogowuje mnie i muszę się ponownie logować:
<?php
$czassesji = (60*60*9);
//error_reporting(0);
include './db_connect.php';
function logowanie() {
if($_SESSION['logowanie'] == 'poprawne') {
$string = '<br /><form action="' . getenv(REQUEST_URI
) . '" method="post">'; $string .= '<input type="submit" class="button" name="wylogowanie" value="Wyloguj" />';
$string .= '</form>';
} else {
$string = '<form action="' . getenv(REQUEST_URI
) . '" method="post">'; if(isset($_SESSION['logowanie'])) $string .= $_SESSION['logowanie'];
$string .= '<table border="0">';
$string .= '<tr>';
$string .= '<td>Login:</td>';
$string .= '<td><input type="text" size="15" class="pole" name="login" /></td>';
$string .= '</tr>';
$string .= '<tr>';
$string .= '<td>Hasło:</td>';
$string .= '<td><input type="password" size="15" class="pole" name="haslo" /></td>';
$string .= '</tr>';
$string .= '<tr>';
$string .= '<td class="footer-login"> </td>';
$string .= '<td align="right"><input type="submit" name="logowanie" class="button" value="ok" /></td>';
$string .= '</tr>';
$string .= '</table>';
$string .= '</form>';
}
return $string;
}
// logowanie
if(isset($_POST['logowanie'])) { $dane = @mysql_query('SELECT login, pass FROM usr WHERE login ="' . $_POST['login'] . '" AND pass = "' . $_POST['haslo'] . '"');
$_SESSION['logowanie'] = 'poprawne';
} else {
$_SESSION['logowanie'] = '<h2>Błędny login lub hasło!</h2>';
}
//unset($_POST['logowanie']);
}
// wylogowanie
if(isset($_POST['wylogowanie'])) { unset($_SESSION['logowanie']); }
if($_SESSION['logowanie'] == 'poprawne') {
// jeśli zalogowany
if (!isset($_COOKIE[hash
])) {
$query = 'SELECT id, login, realname, email FROM usr WHERE login = "' . $_POST['login'] . '"';
$user_id = $info[0];
$login = $info[1];
$realname = $info[2];
$email = $info[3];
}
switch ($_GET['str']) {
...
...
...
break;
}
} else {
// jeśli niezalogowany
}
?>