Hello, regular expression give me a head ache. i need to check if a path is in a path but the first path is not hard coded in, heres what i got
define('MP3_FOLDER', 'F:/FTP/mp3s/');
function hack_check ($allowed_folder, $current_folder) {
if (!eregi(str_replace("/","[\\]", $allowed_folder), realpath(MP3_FOLDER."/".$current_folder))) {
die (HACK_TEXT);
}
}
hack_check(MP3_FOLDER, $path);
now this works if $path is set like say to "game" so the full path would be "f:/ftp/mp3s/game" that will pass with one of the ways i tried but if $path is not set the full path wold be "f:/ftp/mp3s/" and that failes...
soo what i need to get working is something that will pass if MP3_FOLDER is in the realpath'd version ....if that doesn't make sence. i need to make
if (!eregi("F:[\\]ftp[\\]mp3s", realpath($root_folder."/".$path))) {
die ("Bad Hacker, I already thought of that hack ;)");
}
that works into this
define('MP3_FOLDER', 'F:/FTP/mp3s/');
function hack_check ($allowed_folder, $current_folder) {
if (!eregi(str_replace("/","[\\]", $allowed_folder), realpath(MP3_FOLDER."/".$current_folder))) {
die (HACK_TEXT);
}
}
hack_check(MP3_FOLDER, $path);
that doesn't and id like to use preg_match over eregi for speed reasons.
Thanks
Don