htmlspecialchars() - How and when to use and avoid multiple use
Posted
by naescent
on Stack Overflow
See other posts from Stack Overflow
or by naescent
Published on 2010-06-02T11:44:54Z
Indexed on
2010/06/02
11:54 UTC
Read the original article
Hit count: 259
Hi,
I'm building a PHP intranet for my boss. A simple customer, order, quote system. It will be denied access from the Internet and only used by 3 people. I'm not so concerned with security as I am with validation. Javascript is disables on all machines.
The problem I have is this:
- Employee enters valid data into a form containing any of the following
:;[]"'
etc. - Form $_POSTS this data to a validationAndProcessing.php page, and determines whether the employee entered data or not in to the fields. If they didn't they are redirected back to the data input page and the field they missed out is highlighted in red.
- htmlspecialchars() is applied to all data being re-populated to the form from what they entered earlier.
- Form is then resubmitted to validationAndProcessing.php page, if successful data is entered into the database and employee is taken to display data page.
My question is this:
If an employee repeatedly enters no data in step 1, they will keep moving between step 1 and 4 each time having htmlspecialchars() applied to the data.
So that:- &
becomes:- &
becomes:- &
becomes:- &
etc..
How can I stop htmlspecialchars() being applied multiple times to data that is already cleaned?
Thanks, Adam
© Stack Overflow or respective owner