I would add the following: General tips: * Understand how HTTP works (sounds trivial for a PHP developer, but at least here in Brazil, a huge portion doesn't do) * ALWAYS keep php.ini with production settings and replicate the same into your development environment (Vagrant is a great option here) * ALWAYS keep Apache or Nginx configs in sync among every environment * NEVER trust $_SERVER['REMOTE_ADDR'] to get client…
PHP Commandments
61–70 of 117 posts
Re: PHP Commandments
#62#2 I've actually gotten into an argument with someone who insists md5 is perfectly fine for password hashing if you salt it. Better, in fact, because it's faster. So yeah.
#3 Unfortunately we're also stuck with a ton of legacy code that does this, and would be all but impossible to refactor, and i'm still pointing out to people who post code like this to at the very least sanitize their stuff.
Seriously, if it's even possible, someone come up with an easy way to convert old-style linear SQL statements to parameterized queries or something in PHP.
#4 HTMLPurifier is good, but can be incredibly slow. htmlspecialchars is probably good where you don't need to sanitize data but still provide markup. I personally use htmlpurifier after a markup generator like Markdown, so I can enforce a whitelist against it. Still, YMMV but do SOMETHING.
#5 Might as well say don't use Wordpress either. I have yet to find a framework that makes me as angry as it does. Though granted, I haven't actually used cakePHP yet and I hear Zend Framework is a bit gnarly. Though "Use a framework when you can" is probably a good rule. Though eventually that ends up being "don't reinvent the wheel"
#6 WHO EVEN DOES THIS?!
#7 I don't know. Depending on how many you're sending, it's probably fine for low volume. It's probably right though.
#8 Don't really agree with this at all. In a global file, the body of helpful_function() is in one place, so if I want to change it or upgrade it, it's right there. If I integrate it into the rest of my code, I have to go look for it or else deal with multiple definitions in different files.
Though I will agree that if you're only using a helper function once in your code, then clearly it needs to be integrated somewhere else. My definition for a helper function is that it gets used multiple times in no particular place.
#9 Most php developers work with whatever server their host is using, so this is of limited utility.
Re: PHP Commandments
#638. NEVER create a file of useful functions, even if it's called helpers.php This smacks of such a broken thinking process, it makes my teeth itch. If you have commonly-used functions, they should be integrated with the commonly-used parts of your code. Example function used for debugging: function preint_r($arr) { echo ' '; print_r($arr); echo ' '; } Where would something like this fit, if not a general helpers.php t…
>Where would something like this fit, if not a general helpers.php type file? In debugging.php alongside with other debugging helpers?
Re: PHP Commandments
#64> NEVER hash passwords with MD5/SHA-1/Hash-of-the-day > PHPass will make life easy for yourself and keep your users' passwords secure. MD5/3DES/SHA-1 are relatively broken. But saying "use this magical library" is really far from a solution. Who's to say that that library won't be broken tomorrow and then someone else won't write an article next week saying "don't use PHPass!" Programmers just need to stay up-to-date…
>MD5 was very much acceptable for the longest time.
MD5 was never a good password hash. Neither is SHA1,256,etc. The reason is that they are crypto hashes optimized for speed. This is bad for passwords. What you should be using is the opposite: an expensive hash to compute. This is bcrypt which has been in use since 1999 (and what the PHPass is based on). This is a clear example of "Dont do your own crypto" because you dont know all the details.
>It was even what was implemented by the standard libraries and APIs of the time.
Yes, and this was a mistake. But to be fair DES used to take a full second to compute and bcrypt wasnt invented until 1999. This is why current password hashes use variable rounds so that we can increase the cost as computers get faster. When the algorithm is DESIGNED to be computed quickly it is fundamentally broken for passwords.
This is the reason that LinkedIn's passwords were vulnerable[1].
[1]http://www.itworld.com/security/280813/expert-calls-linkedin...
Re: PHP Commandments
#65Re: PHP Commandments
#66The comments pretty much sum up how useful this blog post is... The upvotes merely show how educated a lot of the PHP community isn't
Please don't get confused and paint everybody so broadly, it damages us all. There are many people working hard to improve the language and create a more modern environment around PHP.
Re: PHP Commandments
#67> PHP version 5.5 (not yet released) will support Bcrypt natively via its password_hash() function. Use it. This makes it sound like PHP didn't support bcrypt before 5.5. It did. PHP always has bcrypt support in 5.3 and 5.4. In older versions it also has bcrypt support if the operating system supports it. PHP 5.5 only added a wrapper around the low-level crypt() API, which makes password hashes more convenient to use…
Re: PHP Commandments
#68Are people still using PHP without frameworks these days?
The "cool kids" in PHP are using Laravel 4. It's a well made framework. I'm doing a REST API in it at work and the lack of mind share and docs is probably the worst part about it (it's still in beta to be fair). Most of the time I ended up reading the framework code. PHP leaves a lot to be desired though. It boggles my mind how developers who love what they do have the patience to stick with it. Example: Feature requ…
Re: PHP Commandments
#69> NEVER hash passwords with MD5/SHA-1/Hash-of-the-day > PHPass will make life easy for yourself and keep your users' passwords secure. MD5/3DES/SHA-1 are relatively broken. But saying "use this magical library" is really far from a solution. Who's to say that that library won't be broken tomorrow and then someone else won't write an article next week saying "don't use PHPass!" Programmers just need to stay up-to-date…
Re: PHP Commandments
#70The comments pretty much sum up how useful this blog post is... The upvotes merely show how educated a lot of the PHP community isn't