News for hackers. Stuff that matters.
Re:How I hacked Digg by simonw on Wednesday June 04, 2008 @02:47PM (#209223)
Here's how to safely output a variable in PHP:

<?php echo htmlspecialchars($name); ?>

Here's how to do the same thing in Django:

{{ name }}

That's the thing that bugs me most about PHP: it's not even a productive templating language!

Re:How I hacked Digg by vulpes on Wednesday June 04, 2008 @03:00PM (#209236)
I didn't realize Django is a language. Lets not compare frameworks to languages.
Re:How I hacked Digg by simonw on Wednesday June 04, 2008 @03:15PM (#209259)
I personally think PHP it blurs the line between a language and framework. The "framework" part is the 20,000 builtin functions and the mechanism it provides for executing code as part of a dynamic web request.

In any case, my intent wasn't to compare Django to PHP, it was to point out that PHP's default way of outputting things really does make it inconvenient to write secure code - hence answering the parent post that argued that poor security had nothing to do with the language used.

Re:How I hacked Digg by cstejerean on Wednesday June 04, 2008 @03:45PM (#209305)
Django is a framework, but it also has a language for writing templates, which is what the example above is written in.
Re:How I hacked Digg by yan on Wednesday June 04, 2008 @03:09PM (#209249)
You are comparing apples to oranges. Django is a framework built on Python. Python doesn't provide anything to escape strings. I'm sure there are also PHP frameworks and templating languages which make this very easy.

I realize I'm playing devil's advocate because I love Python, but you shouldn't put blame nor give credit where it isn't due.

Re:How I hacked Digg by simonw on Wednesday June 04, 2008 @03:15PM (#209261)
Re:How I hacked Digg by breck on Wednesday June 04, 2008 @03:21PM (#209272)
Here you go:

function o($name) { echo htmlspecialchars($name); }

o($name);

Re:How I hacked Digg by simonw on Wednesday June 04, 2008 @03:52PM (#209309)
You still need to do this:

<?php o($name); ?>

I've used this exact function in my own code, though I call it "h". Really sucks that we have to do this - not to mention that PHP's global namespace for functions means it's better to have long names that are more likely not to clash with third party code.

Re:How I hacked Digg by ojbyrne on Wednesday June 04, 2008 @06:25PM (#209448)
Actually you can use the <?= syntax to make it even more concise:

function o($name) { return(htmlspecialchars($name));}

<?=o($name)?>

which lo, and behold, looks a lot like the rails candidate below.

Re:How I hacked Digg by simonw on Wednesday June 04, 2008 @07:08PM (#209467)
You can't write code for redistribution like that though as most PHP installations have that option disabled since ti inteferes with XML processing instructions.
Re:How I hacked Digg by fendale on Wednesday June 04, 2008 @02:49PM (#209226)
And in Rails

<%= h(@var) %>