The URL would be
- Saved to a MySQL database
- Used to display a picture on the user’s profile
would strip_tags() and mysql_real_escape_string() be enough?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Enough sanitization” thoroughly depends on what environment you’re talking about. Sanitization for MySQL should be considered entirely separate from sanitization for web output, and you should handle them separately to avoid a lot of hassle.
Sanitizing for MySQL
mysql_real_escape_string()will sanitize a piece of data and make it safe to put inside an SQL query.Sanitizing for output
htmlspecialchars($val)at output time will prevent any malicious tags from being rendered, because<and>characters are converted into their entity representations and not rendered as tag delimiters.ENT_QUOTESmodifier if you are outputting something that is inside an HTML element’s quoted attribute, such as<input name="email" value="<?php echo htmlspecialchars($email,ENT_QUOTES); ?>" />That should be all you need, unless you have special requirements.
strip_tags()shouldn’t really be used for sanitization, as it can be fooled with badly formed HTML. Sanitization is a worthy goal, and if you can keep your contexts separate, you’ll run into fewer problems with data manipulation between them.