0

I have HTML site and we are using PHP code to manage contact page. Currently, we are facing issue with URL injection alert from security scan. Found the issue is with following two lines PHP codes, but unable to validate date input.

<div class="field calendar"><input name="contact-arrival" type="date" placeholder="Arrival Date" id="contact-arrival" value="<?php if (isset($_POST['arrival']) && !empty($_POST['arrival'])) { echo $_POST['arrival']; } else { echo '';} ?>" readonly /><i class="fa fa-calendar-o"></i></div>

<div class="field calendar"><input name="contact-departure" type="date" placeholder="Departure Date" id="contact-departure" value="<?php if (isset($_POST['departure']) && !empty($_POST['departure'])) { echo $_POST['departure']; } else { echo '';} ?>" readonly /><i class="fa fa-calendar-o"></i></div>

1 Answer 1

1

You should escape the posted data using htmlentities:

echo htmlentities($_POST['arrival'], ENT_QUOTES, 'utf-8');

Note: you should also validate the form data once the form is posted to your PHP script.

Sign up to request clarification or add additional context in comments.

2 Comments

After got the post request the form will be validating the input using HTML validation. If you have any other better idea please let me know. Thanks.
Validate on both sides - in the browser AND on the server. Validation in the browser saves sending a request to the server with invalid data. Validation on the server will prevent SQL injection attempts and 'dirty' data from going into your database. You can find out more about data filtering here: phptherightway.com/#data_filtering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.