(i) JavaScript + PHP form validation(dual-validation)
Javascript validation is not secure because anyone can use curl or an equivalent tool to fashion their own HTTP requests, bypassing your Javascript validation.
PHP form validation is good to use, but doesn't work for many cases where you can't filter on a predictable pattern. Basically, most string inputs.
(ii) sha512 password hashing
SHA512 has more bits to it than other SHA hashing functions, but more bits doesn't help against dictionary attacks or rainbow tables or brute force attacks.
You don't mention using salting or iterations, which are recommended. Salting is to prevent someone from building a rainbow table in advance. Iterations are to slow down password validation so attackers can't make millions of attempts per second. Check out password hashing function that automatic key stretching, such as Bcrypt or PBKDF2.
(iii) mysql_real_escape_string
As others have commented, the ext/mysql API is deprecated in PHP, and will be removed soon. It's recommended to start writing code with mysqli or PDO now, so you don't have to rewrite all your apps when ext/mysql is removed (or get stuck unable to upgrade to the next version of PHP).
I find it's easier to stay in good habits if one uses prepared queries with parameters instead of escaping. Both methods are effective if you do them consistently, but many developers want to write code speedily, and worrying about calling the right escaping function and then opening and closing the right quotes as you concatenate variables into your query strings slows us down. Once you get used to it, coding with SQL parameters can be very speedy and less error-prone.
There are still other cases of dynamic SQL, for which neither escaping nor query parameters help. Those solutions are only to include literal values in SQL dynamically. But what if I want to choose a column, an expression, or a whole SQL clause dynamically?
SELECT * FROM MyTable ORDER BY $column_to_sort_by $asc_or_desc
For this, you should be prepared to use whitelisting to allow external inputs to choose dynamic parts, without you having to concatenate external input directly into your SQL. See my presentation SQL Injection Myths and Fallacies for more examples.
Finally, all your methods focus on protecting SQL statements. What about other code injection vectors like eval()
? Or other more subtle cases (see the thread Exploitable PHP functions? on StackOverflow)?
What about security vulnerabilities from outputting unencoded HTML (also known as cross-site scripting or XSS)? You can find more information on common vulnerabilities at the OWASP Top 10 Project or the CWE / SANS Top 25 Most Dangerous Software Errors.