How to make it so that by pressing submit'ov you don’t have to refresh the page additionally and work right after clicking on the button?
Here is the code:
<?php $connect=mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("my_bd"); //Обработка входа if(isset($_POST['authorization'])) { $e_login = $_POST['e_login']; setcookie("e_login", $e_login, time()+3600); $e_password=md5($_POST['e_password']); $query=mysql_query("SELECT * FROM user WHERE login='$e_login'"); $user_data=mysql_fetch_array($query); if($user_data['password'] == $e_password){ $check=true; } else{ $check=false; } } //Обработка выхода if(isset($_POST['logout'])) { $e_login=$_COOKIE['e_login']; setcookie("e_login", $e_login, time()-3600); } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Работа с куками</title> </head> <body> <?php if(isset($_COOKIE['e_login'])){ echo "Кука существует(",$_COOKIE['e_login'],")<br>"; echo "Авторизация прошла успешно"; echo '<form method="post" action="22.php"> Привет, '. $_COOKIE['e_login'].' <br>Хотите выйти? <br> <input type="submit" name="logout" value="Выйти" /> </form>'; } else{ echo '<form method="post" action="22.php"> Привет, Гость Пожалуйста авторизуйся <br> <input type="text" name="e_login" placeholder="e_login"> <input type="text" name="e_password" placeholder="e_password"> <input type="submit" name="authorization" value="Отправить" /> </form>'; } ?> </body> </html>
setcookiedoes not put a value in$_COOKIE, it simply creates an HTTP header. Therefore, you need to take care of yourself so that the necessary data is in$_COOKIE. - etki