I have a question about “link control system” in PHP. The idea is to make script that could make different links than original – something like friendly links with .htaccess. In .htaccess make rule to redirect all traffic to script file – for example linkprocessor.php then in this file should be some conditions, mysql connect and pattern grabber from database(friendlyurl and originalurl columns). So if we write full address – example.com/defined-address it will redirect us(but not change address) to linkprocessor.php and then script is checking if /defined-address is in database, if is it will include certain(based on friendlyurl) originalurl file. Is that script would be optimal? That script could prevent from “hackers”.
Example:
example.com/defined-address -> linkprocessor.php -> SELECT originalurl from table WHERE friendlyurl = /defined-address -> include originalurl
=> can be written incoherently but its hard to explain that precisely
What you are asking about here is the Front Controller pattern http://en.wikipedia.org/wiki/Front_controller.
There are various ways to implement it, using a sql database to map URI strings to files to include is a valid way to do it, but might be overkill. The same information could probably be hard coded in a php array.
The standard way to prevent hackers is to only allow whitelisted files to be included. In your case you are using an explicit map to determine which page to include, so it is not an issue.
Some code to get you started: