Skip to content

Instantly share code, notes, and snippets.

@johnmorris
Created June 18, 2015 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmorris/03bd85c3f9354dc07327 to your computer and use it in GitHub Desktop.
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
<?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