php - Send echo before sleep not working, any alternatives? -
php - Send echo before sleep not working, any alternatives? -
i'm confused do. want send echo, ajax read , react to. problem php script executed before echoes. tried flushing , other methods found on sof still didn't work. think it's because free host server 000webhost - may have conflicts sleep function.
is there way delay execution of php script, before completion send echo client (which alerts user), , afterwards script execute while submit button disabled , time delay displayed?
please excuse noviceness on ajax, i've started learning it.
if ($failed_attempts_ip_user >= $first_throttle_limit) { foreach ($throttle $attempts => $delay) { if ($failed_attempts_ip_user > $attempts) { if (is_numeric($delay)) { $next_login_minimum_time = $latest_attempt + $delay; if (time() < $next_login_minimum_time) { $remaining_delay = $next_login_minimum_time - time(); echo "you must wait " . $remaining_delay . " seconds before next login attempt."; sleep($remaining_delay); } else { homecoming "safe login"; } } else { if ($delay === "recaptcha") { echo 'recaptcha'; } else { //$max_attempt = array_search('temp_blocked', $throttle); // search key 'temp_blocked' index. echo "too many login attempts detected. please wait " . $temp_block_attempts_limit . " minutes before next attempt."; } } break; } } // foreach close tag echo "email/username and/or password incorrect."; exit; } echo "user_password_does_not_match"; }
ajax:
$(function ajaxlogin() { $("#login_form").submit(function(e) { e.preventdefault(); $("input[name='submit']").val("processing..."); $("input[name='submit']").addclass("disablebutton"); $("input[name='submit']").prop("disabled", true); var receivedatalogin = $.ajax({ datatype: "text", type: "post", url: 'includes/login_script.php', timeout: 5000, data: $(this).serialize() }); receivedatalogin.done(function(data){ if(data.trim() == "empty_email_username_detected") { alert("please come in in email address."); } else if(data.trim() == "empty_password_detected") { alert("please come in in password."); } else if(data.trim() == "temp_block_detected") { alert("too many login attempts. please seek 1 time again in 15 minutes."); } else if(data.trim() == "successfully_logged_in") { $('.form_menu_wrapper').slideup(200); alert("you have signed in successfully!"); } else if(data.trim() == "email/username and/or password incorrect.") { alert("your email address/username and/or password incorrect."); } else if(data.trim() == "user_password_does_not_match") { alert("your email address/username and/or password incorrect."); } else if(data.trim() == "you must wait 1 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 1 sec before next login attempt."); } else if(data.trim() == "you must wait 2 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 2 seconds before next login attempt."); $("input[name='submit']").val("sign in"); } else if(data.trim() == "you must wait 4 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 4 seconds before next login attempt."); } else if(data.trim() == "you must wait 8 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 8 seconds before next login attempt."); } else if(data.trim() == "you must wait 16 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 16 seconds before next login attempt."); } else if(data.trim() == "you must wait 20 seconds before next login attempt.email/username and/or password incorrect.") { alert("you must wait 20 seconds before next login attempt."); } else if(data.trim() == "recaptchaemail/username and/or password incorrect.") { alert("recaptcha -- add together recaptcha later"); } else if(data.trim() == "too many login attempts detected. please wait 15 minutes before next attempt.email/username and/or password incorrect.") { alert("too many failed login attempts detected. please wait 15 minutes before next attempt."); } else { alert("error. please seek 1 time again later."); } $("input[name='submit']").val("sign in"); $("input[name='submit']").removeclass("disablebutton"); $("input[name='submit']").prop("disabled", false); });
you can't send partial responses client; response not sent until code finished executing.
you should keeping track of user's session , how long need wait before logging in persistently on server. way code can executed across multiple requests (instead of trying stream responses client socket-style while causing php script sleep—it won't work).
php ajax echo sleep
Comments
Post a Comment