php - Protecting my forms against XSS attacks -


register.php

    $_session['email'] = $_post['remail'];     $_session['first_name'] = $_post['firstname'];     $_session['last_name'] = $_post['lastname'];      $first_name = $mysqli->escape_string($_post['firstname']));     $last_name = $mysqli->escape_string($_post['lastname']);     $email = $mysqli->escape_string($_post['remail']);     $password = $mysqli->escape_string(password_hash($_post['rpassword'], password_bcrypt));     $confirmpassword = $mysqli->escape_string(password_hash($_post['confirmpassword'], password_bcrypt));     $hash = $mysqli->escape_string(md5(rand(0,1000)));      $result = $mysqli->query("select * users email='$email'") or die($mysqli->error());      if ($result->num_rows > 0)     {         $_session['message'] = '<div class="info-alert">user email exists!</div>';         header("location: error.php");     }       else {         $sql = "insert users (first_name, last_name, email, password, hash)"              ."values ('$first_name','$last_name','$email','$password', '$hash')"; 

i new php , coding. problem don't know how use htmlspecialchars prevent against basic xss attacks.

how can this?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -