Live data from Hacker News

46 useful PHP code snippets

blog.koonk.com

11–20 of 26 posts

Re: 46 useful PHP code snippets

#11
post #5
post #2

I stopped at #3...using stripslashes is not an acceptable deterrent by any means. I am also unsure how htmlentities has anything to do with SQL injection...maybe you meant XSS prevention? I chose not to read the rest.

Yeah, just logged in to say that. Author probably never heard of PDO and parametrized queries...

If he ever visit this page, some not too outdated articles about PHP:

http://www.phptherightway.com/ http://fabien.potencier.org/php-is-much-better-than-you-thin...

Re: 46 useful PHP code snippets

#14

This doesn't look like the most professionally put together set of snippets I've ever seen. For example: function is_validemail($email) { $check = 0; if(filter_var($email,FILTER_VALIDATE_EMAIL)) { $check = 1; } return $check; } is a long-winded way of doing: function is_validemail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) ? 1 : 0; }

from teh function name, i would expect boolean as return type.

Re: 46 useful PHP code snippets

#15
post #2

I stopped at #3...using stripslashes is not an acceptable deterrent by any means. I am also unsure how htmlentities has anything to do with SQL injection...maybe you meant XSS prevention? I chose not to read the rest.

In addition to stripslashes being woefully inadequate, the vast majority of these are demonstrations of cURL + some API. The PHP aspect is tertiary.

Re: 46 useful PHP code snippets

#16
post #14

This doesn't look like the most professionally put together set of snippets I've ever seen. For example: function is_validemail($email) { $check = 0; if(filter_var($email,FILTER_VALIDATE_EMAIL)) { $check = 1; } return $check; } is a long-winded way of doing: function is_validemail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) ? 1 : 0; }

from teh function name, i would expect boolean as return type.

Yeah, I would too.

Re: 46 useful PHP code snippets

#18
post #2

I stopped at #3...using stripslashes is not an acceptable deterrent by any means. I am also unsure how htmlentities has anything to do with SQL injection...maybe you meant XSS prevention? I chose not to read the rest.

You chose wisely. What is this _thing_ doing here?

Many snippets are of questionable quality. Also, any decent programmer should be able to come up with all of them and implement them more cleanly.

Oh, and please people, don't use snippets like those without checking the services first (in the case of the emails, SMS). Just go to the page of the company offering the service, read the documentation AND also read the terms of service.

Jeesh.

Re: 46 useful PHP code snippets

#20
post #14

This doesn't look like the most professionally put together set of snippets I've ever seen. For example: function is_validemail($email) { $check = 0; if(filter_var($email,FILTER_VALIDATE_EMAIL)) { $check = 1; } return $check; } is a long-winded way of doing: function is_validemail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) ? 1 : 0; }

from teh function name, i would expect boolean as return type.

Well, it basically is due to type juggling.
Post reply on HN