index.php
"http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="jquery.js" type="text/javascript"></script> <title>New Web Project</title> <script> function zaloguj(){ $.ajax({ type: 'POST', url: 'ajaxLogowanie.php', data: 'login='+$("#login").val()+'&haslo='+$("#haslo").val(), success: function(data) { if(data=='false'){ $('#info').fadeIn('slow'); setTimeout( function() { $('#info').fadeOut('slow'); }, 3000); }else{ location.href = 'zalogowany.php'; } } }); return false; } </script> </head> <body> <form onsubmit="return zaloguj()"> Login: <input type="text" id="login" name="login" /> <br /><br /> Haslo: <input type="password" id="haslo" name="haslo" /><br /> <input type="submit" value="Zaloguj" /> </form> <div id="info" style="display: none;"> Podałeś niepoprawne dane! </div> </body> </html>
auth.php
<?php if($_SESSION['zalogowany']==1){ }else{ } ?>
ajaxLogowanie.php
<?php $zap="SELECT haslo FROM user WHERE login='".$_POST['login']."'"; $haslo=$pass[0]; $login=$_POST['login']; $zalogowany = 'false'; $usr = $_POST['login']; $pass = $_POST['haslo']; if (($usr==$login)&($pass==$haslo)){ $_SESSION['zalogowany']=1; $zalogowany = 'true'; }else{ $zalogowany = 'false'; } ?>
ajaxWylogowanie.php
<?php $_SESSION['zalogowany']==0 ?>
zalogowany.php
<?php include 'auth.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="jquery.js" type="text/javascript"></script> <title>New Web Project</title> <script> function wyloguj(){ $.ajax({ type: 'POST', url: 'ajaxWylogowanie.php', success: { location.href = 'index.php'; } } }); return false; } </script> </head> <body> Strona dostępna po zalogowaniu <form onsubmit="return wyloguj()"> <input type="submit" value="Wyloguj" /> </form> </body> </html>
Najprawdopodobniej błąd leżey w ajaxWylogowywanie.php i zalogowany.php ew. jeszcze w auth.php