Jump to content

CGI Scripts preg_match


Mr.Shawn

Recommended Posts

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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.