Created
June 18, 2015 13:22
-
-
Save johnmorris/03bd85c3f9354dc07327 to your computer and use it in GitHub Desktop.
Prevent XSS attacks using htmlspecialchars and htmlentities. Full video tutorial here: http://youtu.be/pc0V9hJpE54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _e($string) { | |
echo htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); | |
//echo htmlentities($string, ENT_QUOTES, 'UTF-8'); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Escape Output</title> | |
</head> | |
<body> | |
<?php _e('This is a problem: <script>alert("Yikes");</script>'); ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment