How to prevent cross site scripting

前端 未结 2 1349
一整个雨季
一整个雨季 2020-12-18 11:20

I have the following form that users fill in:

2条回答
  •  情深已故
    2020-12-18 11:30

    this is called security issue. Cross site scripting, you have many methods to avoid it,

    What's the best method for sanitizing user input with PHP?

    For example if you have a option to input an email address you have to validate it like below:

    
    

    If there is a option to enter a string then you ave to validate like below

    
    

    In your case you have to do something like below

    $Name = htmlentities($_POST['Name']);
    $email = htmlentities($_POST['email']);
    

    Instead of above, follow filter sanitizing method:

    $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    $Name = trim(filter_var($_POST['Name'], FILTER_SANITIZE_STRING));
    

提交回复
热议问题