PHP : Detecting USB device
I'm trying to use PHP to store username and password to a text file on a USB thumb drive. So when user comes back to sign in with USB key a pop should op开发者_C百科en and should prompt for username and password. So my question is how can i detect the USB thumbdrive using PHP. So it is possible with Client or ServerSide. And my Operating system is Windows 7.
I found similar question on stackoverflow about using shell scripting,but could'nt understand,so can some help me understand
Edit: I asked for explanation from possible duplicate question , and please dont vote for closing this question !!!
What you are trying to accomplish is possible (impossible ideas are pretty rare)
How you are trying to accomplish it is not. This definitely shows the neophyte programmer "bit off more than you can chew" mentality. You cannot grab data from the client. They can, however, push it to you -
You could create a small autorun.ini file or something similar for a USB drive that would actively open a browser window on the client pointed to a page on your site to handle authentication. The specifics of such an implementation would be quite verbose and steeped in security challenges, but this is possible.
Like I said, what you are trying to do is definitely possible. Don't get discouraged when you ask how to do something and are told it's impossible. Find out why it's "impossible" - it may not be. If it is, find out how other people would do it, and go from there.
You cannot do it on the client side. I repeat You CANNOT do it with PHP on client side.
Sure, you could have a PHP script run when a thumb drive is inserted - but the PHP code would have to be installed on the machine you want this to happen on, the script would have to be registered as an application capable of being an auto-run target, and have to set up to be the default handler for USB thumb drives.
If you want the code to run on a web server somewhere and do this via a browser, then... no. Allowing remote (and random) webservers to see what's happening at the hardware level on a client's PC would be worse than a nightmare as far as security is concerned.
that's impossible.
Not with PHP which is thousands miles from your flash-drive,
Nor with Js, for obvious security reasons
PHP cannot make determinations about the OS on its own. Even though the other post suggests using actual bash scripts through shell_exec
, I don't even think that would work as it would only have access to the server, so unless you're actually plugging the USB into the server, you're out of luck. If you are running a php script locally, you can do it by using command line exec functions, and you might even be able to read the USB files by accessing the correct drive through PHP (and you would have to keep polling for this drive).
If you are trying to do this over an internet connect, you can't, unless you can ssh to the local computer. Highly unlikely. As said in other answers, JS does not have access to local drives in most modern browsers.
精彩评论