How to check an exectuable's path is correct in PHP?

Posted by nickf on Stack Overflow See other posts from Stack Overflow or by nickf
Published on 2010-06-08T03:59:12Z Indexed on 2010/06/08 4:02 UTC
Read the original article Hit count: 131

Filed under:
|
|

I'm writing a setup/installer script for my application, basically just a nice front end to the configuration file. One of the configuration variables is the executable path for mysql. After the user has typed it in (for example: /path/to/mysql-5.0/bin/mysql or just mysql if it is in their system PATH), I want to verify that it is correct. My initial reaction would be to try running it with "--version" to see what comes back. However, I quickly realised this would lead to me writing this line of code:

shell_exec($somethingAUserHasEntered . " --version");

...which is obviously a Very Bad Thing. Now, this is a setup script which is designed for trusted users only, and ones which probably already have relatively high level access to the system, but still I don't think the above solution is something I want to write.

Is there a better way to verify the executable path? Perhaps one which doesn't expose a massive security hole?

© Stack Overflow or respective owner

Related posts about php

Related posts about security