My script:
$secret = check_input($_GET['secret']);
if(isset($_POST['register'])) {
if (isset($secret) || !empty($secret)) {
if (file_exists(ROOT . '/intl/codes/' . $secret)) {
unlink(ROOT . '/intl/codes/' . $secret);
$trusted = 'yes';
} else {
$trusted = 'no';
}
}
//$_POST['register'] register details...
}
- Is there another way to do it (simplier, etc.)?
- If
$secretdoesn’t exist in the/codes/folder, it producesWarning: unlink Is a directoryHow to get rid of that? - Why
$trustedalways givesyeseven if the file doesn’t exist ?
To delete a directory, you should be using
rmdir()instead ofunlink().Although, there is a serious security risk here! If your
check_input()does not properly sanitize$secret, you couldrmdir('/intl/codes/../')which is the same as deleting /intl/.Try something like this: