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> 
  • jquery Ajax - terantul
  • setcookie does 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
  • @terantul header ('Location: testwork / 22.php' ); can i use - Stein_
  • header ('Location - this is the same page reload. If you need to update / create a cookie, you will need to reload the page. If there are changes on the page from the presence / value of the cookie (for example, information about the user’s status is logged in or not), you can create a cookie also update the block with information via ajax - terantul

1 answer 1

You can do this:

  1. signin.php - a page for entering a login and password and submit to signin-check.php
  2. signin-check.php - page for checking login and password, setting cookies and / or session values, as well as redirect to home
  3. index.php - home page

Those. hands it is not required to update, but not to do without a redirect.