I want to make authorization on sessions in PHP. The script below causes errors:
When logging in:
[17-Aug-2012 14:48:33] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/[...]/index.php on line 37
When exiting the script: (index.php? Logout)
[17-Aug-2012 14:49:39] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/[...]/index.php on line 37
[17-Aug-2012 14:49:39] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/[...]/index.php on line 42
And to exit does not redirect to index.php
header ("Location: index.php");
<?php function draw_form($bad_login = false) { ?> <form action="" method="post"> <input type="text" name="login"></input><br/> <input type="password" name="pass"></input> <input type="submit" name="submit"></input> </form> <?php if ($bad_login) echo 'неправильный логин и/или пароль'; } function check_login($login, $pass) { return ($_POST['login'] == 'admin') && ($_POST['pass'] == '565656'); } session_start(); if (isset($_GET['logout'])) { session_unset(); session_destroy(); header("Location: index.php"); exit(); } if (!isset($_SESSION['login'])) { $login = $_POST['login']; $pass = $_POST['pass']; if (count($_POST) <= 0) draw_form(); else { if (check_login($login, $pass)) $_SESSION['login'] = $login; else draw_form(true); } } isset($_SESSION['login']) or die(); ?>
How can I fix it? I do not understand what could be the case ...