Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
5968344e
Commit
5968344e
authored
Apr 15, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docs] some docs for escape()
parent
8fe0dcac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
doc/usage.rst
doc/usage.rst
+37
-0
No files found.
doc/usage.rst
View file @
5968344e
...
...
@@ -343,6 +343,43 @@ you can create by calling the ``redirect`` method::
This will redirect from ``/`` to ``/hello``.
Security
--------
Make sure to protect your application against attacks.
Escaping
~~~~~~~~
When outputting any user input (either route variables GET/POST variables
obtained from the request), you will have to make sure to escape it
correctly, to prevent Cross-Site-Scripting attacks.
* **Escaping HTML**: PHP provides the ``htmlspecialchars`` function for this.
Silex provides a shortcut ``escape`` method::
$app->get('/name', function() use ($app) {
$name = $app['request']->get('name');
return "You provided the name {$app->escape($name)}.";
});
If you use the Twig template engine you should use its escaping or even
auto-escaping mechanisms.
* **Escaping JSON**: If you want to provide data in JSON format you should
use the PHP ``json_encode`` function::
use Symfony\Component\HttpFoundation\Response;
$app->get('/name.json', function() use ($app) {
$name = $app['request']->get('name');
return new Response(
json_encode(array('name' => $name)),
200,
array('Content-Type' => 'application/json')
);
});
Pitfalls
--------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment