I’m using:
<?php
$file = $_GET['page']; //ie: http://localhost/?page=index
include "php/{$file}.php";
?>
But I need to know what is the safest way to trim the $file variable befor calling include.
I was thinking about something like:
//-replace '.' with ''
//-replace '/' with ''
//-replace '\' with ''
But I’m sure there is a better way of doing, so I’m asking for your help, please.
I need it to be very secure.
Thank you.
If you need to be very secure, don’t include it as it comes, even after trimming. Instead, use a dicitionary-like association between the variable you get and the file you need to include:
This way, you will never get any unexpected includes.