PHP Securely Save Passwords in Your Database

To securely save passwords in your database you should use password_hash()! When the user registers, you hash the password and then save it to the database: // Create the hashed password from the user submitted password // Notice that we hash() the password using sha256 before creating the hashed password   $hashed_password = password_hash(hash("sha256", trim($_POST["password"])), […]

Redirect 404 Errors to Homepage with Nginx

You can redirect 404 errors to homepage with Nginx. To do so, just add this inside server {}: # Redirect 404 errors to homepage error_page 404 = @myownredirect; # My custom 302 redirect to homepage location @myownredirect { return 302 /; }# Redirect 404 errors to homepage error_page 404 = @myownredirect; # My custom 302 […]

Bash Script to Dump a MySQL Table into a CSV File

Simple bash script to dump a MySQL table into a CSV file: mysql dbname -u’user’ -p’password’ <<QUERY_INPUT SELECT field1, field2, field3, field4 FROM table_name INTO OUTFILE ‘/path/file.csv’ FIELDS ENCLOSED BY ‘"’ TERMINATED BY ‘,’ ESCAPED BY ‘"’ LINES TERMINATED BY ‘\r\n’; QUERY_INPUTmysql dbname -u’user’ -p’password’ <<QUERY_INPUT SELECT field1, field2, field3, field4 FROM table_name INTO OUTFILE […]

How to block CuteStat from crawling your website

CuteStat shows traffic statistics, but it is bad for your website! It steals your page title and thus also your position on Google searches! To block CuteStat from crawling your website, add this on robots.txt: User-agent: * Allow: /   User-agent: CuteStat Disallow: /User-agent: * Allow: / User-agent: CuteStat Disallow: / In case your website […]

How to Test Robots.txt via Google Search Console

First register your website on Google Search Console: https://search.google.com/search-console/about Then browse to this Robots Testing Tool: https://www.google.com/webmasters/tools/robots-testing-tool Select the property (website) and test your Robots.txt. You can test if a web page is blocked by Googlebot.

PHP Generate Secure Random Passwords

This simple PHP function can generate secure random passwords: function generate_strong_password($length = 15, $symbols = array("!", "#", "=", "@", "+", "(")) { $characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;   $charactersLength = strlen($characters);   $randomString = ”;   // Generate the random alphanumeric string for ($i = 0; $i < $length; $i++) $randomString .= $characters[random_int(0, $charactersLength – 1)];   […]

Google Cloud SQL and Public IP Address Security

When you create a SQL cloud instance and you use a public IP address (external IP) on the SQL instance, make sure that your Compute Engine instances that will connect to the public IP of the SQL instance will have a static IP address and not temporary, else if the IP address is temporary it […]

How to use Highlight.js to highlight code

Using Highlight.js to highlight code is simple: First include this inside the HEAD tag of the HTML page: <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/darcula.min.css" /> <script>hljs.initHighlightingOnLoad();</script><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/darcula.min.css" /> <script>hljs.initHighlightingOnLoad();</script> Then you can use it like this: <code class="json"> {name: "John", age: 31, city: "New York"} </code><code class="json"> {name: "John", age: 31, city: "New […]

Nginx HTTP to HTTPS and non-www to www behind Google Load Balancer

First create two forwarding rules on Google Load Balancer (frontend): – One for HTTPS (port 443) traffic – One for HTTP (port 80) traffic Then make sure both rules use the same static IP address. Now on the Compute Engine backend, edit the Nginx config file: server { listen 80; server_name localhost; access_log /var/www/nginx/logs/access.log main; […]

Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region

If you get this error message when you try to create a new Compute Engine instance: Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region…Quota ‘IN_USE_ADDRESSES’ exceeded. Limit: 8.0 in region… Then it looks like you reached the quota of IP addresses in use. To solve this, you need to ask to modify the quota of: This […]