Mr.Shawn Posted March 30, 2008 Share Posted March 30, 2008 Hello guys, I'm trying to do a checking of the filename provided such that it is not a CGI scripts. How do I check it with preg_match? Currently I do have the following for checking php but I wonder how can I check for other extensions such as .js, .html, etc. if (preg_match('/php/i', substr($file, -3))) { die("PHP file not downloadable"); exit; } Quote Link to comment Share on other sites More sharing options...
dsaba Posted March 31, 2008 Share Posted March 31, 2008 preg_match('~\.cgi$~im', $string); Really I would check the mime type or file type with some other php function, or check the headers of the file itself by reading it, people can still change their extensions to whatever they want, but the content (headers) of the file never lies. Quote Link to comment Share on other sites More sharing options...
Mr.Shawn Posted April 1, 2008 Author Share Posted April 1, 2008 preg_match('~\.cgi$~im', $string); Hi dsaba, the regex doesn't works tho. It still allows php file to be downloaded. Quote Link to comment Share on other sites More sharing options...
dsaba Posted April 1, 2008 Share Posted April 1, 2008 I hope you realize I don't know what you mean when you say "doesn't work". Quote Link to comment Share on other sites More sharing options...
Mr.Shawn Posted April 2, 2008 Author Share Posted April 2, 2008 It means that the code you provided is not working and it does not validate CGI scripts? Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted April 2, 2008 Share Posted April 2, 2008 What about: <?php $p = pathinfo($file); if ($p['extension'] == 'cgi'): die("PHP file not downloadable"); exit; endif; ?> Quote Link to comment Share on other sites More sharing options...
Mr.Shawn Posted April 2, 2008 Author Share Posted April 2, 2008 Looks like that's the only way. Thanks lordfrikk. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.