Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Extra whitespace?
    primarykey
    data
    text
    <p>I'm using AJAX to process my ChangePassword class, which extends my DataProcessor class. Everything I get from my AJAX response is somehow having a huge whitespace added before it, maybe equivalent to 10 spaces. The following is my ChangePassword class:</p> <pre><code>&lt;?php require_once "../support/RequiredClasses.php"; class ChangePassword extends DataProcessor { private $_old_password; private $_new_password_1; private $_new_password_2; private $_password_enc; //============================================================================================================================================ Class Constrcutor public function __construct($_old_password,$_new_password_1,$_new_password_2){ try { $_DM = new DataManager(); $this-&gt;_conn = $_DM-&gt;connect(); $this-&gt;_old_password = filter_var($_old_password, FILTER_SANITIZE_STRING); $this-&gt;_new_password_1 = filter_var($_new_password_1,FILTER_SANITIZE_STRING); $this-&gt;_new_password_2 = filter_var($_new_password_2,FILTER_SANITIZE_STRING); if (!$_old_password OR !$_new_password_1 OR !$_new_password_2) {throw new Exception("You have not filled in all of the fields.");} if ($this-&gt;_new_password_1 != $this-&gt;_new_password_2){throw new Exception("The two new passwords you entered do not match.");} if (!isset($this-&gt;_new_password_1[7])) {throw new Exception("Your new password must be at least 8 digits in length.");} $this-&gt;_old_password_enc = $_DM-&gt;encrypt($this-&gt;_old_password,1,$_SESSION["user_email"]); if (!$this-&gt;verifyPassword()) {throw new Exception("The old password you entered was incorrect.");} $this-&gt;_new_password_enc = $_DM-&gt;encrypt($this-&gt;_new_password_1,1,$_SESSION["user_email"]); $this-&gt;_access = $this-&gt;makeChanges(); } // end try catch (Exception $_exception){$this-&gt;_errors[] = $_exception-&gt;getMessage();} } // end __construct public function ChangePassword(){$this-&gt;__construct($_old_password,$_new_password_1,$_new_password_2);} //============================================================================================================================================ Changing Password protected function makeChanges(){ $_update = $this-&gt;_conn-&gt;prepare("UPDATE users SET password=? WHERE user_id=?"); if (!$_update){return FALSE;} $_update-&gt;bind_param("si",$this-&gt;_new_password_enc,$_SESSION["user_id"]); $_update-&gt;execute(); $_update-&gt;free_result(); return TRUE; } // end makeChanges //============================================================================================================================================ Verifying Old Password private function verifyPassword(){ $_verify = $this-&gt;_conn-&gt;prepare("SELECT role_id FROM users WHERE user_id=? AND password=? LIMIT 1"); $_verify-&gt;bind_param("is",$_SESSION["user_id"],$this-&gt;_old_password_enc); $_verify-&gt;execute(); $_verify-&gt;bind_result($_fetched_result); $_verify-&gt;fetch(); $_verify-&gt;free_result(); return ($_fetched_result) ? TRUE : FALSE; } // end verifyPassword } // end class ChangePassword if (isset($_POST["q"]) AND $_POST["q"] == 1){ $_ChangePassword = new ChangePassword($_POST["old_password"],$_POST["new_password_1"],$_POST["new_password_2"]); if (count($_ChangePassword-&gt;_errors)){echo $_ChangePassword-&gt;returnErrors();} else { echo "Success changing password."; } // end else } // end if ?&gt; </code></pre> <p>The next is my DataProcessor class:</p> <pre><code>&lt;?php abstract class DataProcessor { public $_conn; // database connection public $_access; // whether or not the user has access public $_errors = array(); // class-generated errors //============================================================================================================================================ Returning a String of All Errors public function returnErrors(){ $_error_string = ""; foreach ($this-&gt;_errors as $_error){$_error_string .= $_error;} return $_error_string; } // end returnErrors } // end abstract class DataProcessor ?&gt; </code></pre> <p>Finally, my AJAX code:</p> <pre><code>var request; prepareAJAX(); function prepareAJAX(){ request = new XMLHttpRequest(); } // end prepareAJAX function submitChangePassword(){ var old_password = document.getElementById("cp_old_password").value; var new_password_1 = document.getElementById("cp_new_password_1").value; var new_password_2 = document.getElementById("cp_new_password_2").value; var vars = "q=1&amp;old_password="+old_password+"&amp;new_password_1="+new_password_1+"&amp;new_password_2="+new_password_2; request.open("POST","../classes/class.ChangePassword.php"); request.setRequestHeader("Content-type","application/x-www-form-urlencoded"); request.onreadystatechange = function(){ if (request.readyState == 4 &amp;&amp; request.status == 200){ var return_data = request.responseText; alert(return_data); var type = (return_data.charAt(0) == "1") ? "error" : "success"; lightboxNotice("cp",type,return_data); } // end if } // end function request.send(vars); } // end submitChangePassword function lightboxNotice(prefix,type,message){ switch(type){ case "error": document.getElementById(prefix+"_lightbox_notice").className = "ligthbox_notice lightbox_error"; break; case "message": document.getElementById(prefix+"_lightbox_notice").className = "ligthbox_notice lightbox_message"; break; case "success": document.getElementById(prefix+"_lightbox_notice").className = "ligthbox_notice lightbox_success"; break; } // end switch document.getElementById(prefix+"_lightbox_notice").style.display = "block"; document.getElementById(prefix+"_lightbox_notice").style.visibility = "visible"; document.getElementById(prefix+"_lightbox_notice").style.opacity = 1; printNotice(prefix,type,message); } // end lightboxNotice function printNotice(prefix,type,message){ switch(type){ case "error": document.getElementById(prefix+"_notice").className = "notice_error"; break; case "message": document.getElementById(prefix+"_notice").className = "notice_message"; break; case "success": document.getElementById(prefix+"_notice").className = "notice_success"; break; } // end switch document.getElementById(prefix+"_notice").style.display = "block"; document.getElementById(prefix+"_notice").style.visibility = "visible"; document.getElementById(prefix+"_notice").style.opacity = 1; document.getElementById(prefix+"_notice").innerHTML = message; } // end printError </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload