session_start(); if ( !$_SESSION['key'] ) { $alphabet = 'abcdefghiklmnopqastuvwxyz'; for ( $i = 0; $i < 10; $i++ ) { if ( rand( 0, 1 ) == 0 ) { $_SESSION['key'] .= rand( 1, 9 ); } else { if ( rand( 0, 1 ) == 0 ) { $_SESSION['key'] .= strtolower( $alphabet[rand ( 0, 24; )] ); } else { $_SESSION['key'] .= strtoupper( $alphabet[rand ( 0, 24; )] ); } } } } if ( $_POST['text'] && $_POST['key'] ) { if ( !$_POST['key'] OR $_POST['key'] != $_SESSION['key'] ) $errors[] = 'Ошибка сессии!'; if ( !$_POST['text'] ) $errors[] = 'Ошибка, введите текст сообщения!'; if ( $errors ) { foreach ( $errors as $error ) { echo $error . '<br/>'; } } else { } } else { echo '<form action='?' . session_name() . '=' . session_id() . '' method='post'> Сообщение: <br/> <input type='text' name='text'/> <br/> <input type='hidden' name='key' value='' . $_SESSION['key'] . ''/> <br/> <input type='submit' value='Отправить'/> </form>'; }