Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Dickens
18,352 PointsFilter input, escape output
ok so I get the 'filter input', but what does Alena mean by 'escape output'?
3 Answers
Jeffrey van Rossum
2,994 PointsIt prevents using output you might not to be used (echo'd for example).
Let's say you would want to retrieve a name value from a GET parameter. Someone might instead set Javascript code as the name value, like: http://yourwebsitedomain.nl/?name=<script>alert('Evil stuff');</script>
If you simply echo out the value without escaping, the Javascript code gets executed. So you don't want to do this:
<?php
echo $_GET['name'];
This code might do evil things, you wan't to prevent that of course. So instead we make sure no code is being echo'd by escaping the output, like this:
<?php
echo filter_input( INPUT_GET, 'name', FILTER_SANITIZE_STRING ); // strip code from string
Jeremy Antoine
15,785 PointsHere is a good link that helps explain output escaping.
Steven Price
15,120 PointsHi im not sure of the difference between filtering input and escaping output - if you filter input from a user e.g. PHP filter_input and display it in a forum surely you don't need to also escape using htmlentities()? isnt it the same thing?
Andrew Dickens
18,352 PointsAndrew Dickens
18,352 Pointsok Jeffrey you have added a filter, (you have filtered the input) I get that, but what is the escape part?