The reason that I gave the $_SERVER solution is because you referred to this tutorial:
If you just want to filter the database, then it is better to follow this