Languages :: PHP :: cdrom's unique identifier |
|||
| By: guydeschepper |
Date: 09/04/2003 00:00:00 |
Points: 100 | Status: Answered Quality : Excellent |
|
I want to uniquely identify a cdrom, so that I can store its data in a mysql db and retrieve it when the cd is inserted again. Any ideas how I can uniquely identify a cd by using php ? Guy |
|||
| By: VGR | Date: 09/04/2003 16:55:00 | Type : Comment |
|
| first of all, I ***hope*** you know this could work only on the SERVER's cdrom drive ! ;-) then there's no solution but to call the underlying system. You didn't say which OS/platform you used. on Windows, a single execution of "dir F:" (where F: is the drive letter of your CD-ROM drive, of course) leads to getting output : Le volume dans le lecteur C s'appelle C2GOFATBOOT Le numéro de série du volume est 5C40-328D the volumeID (5C40-328D) is what you want. (NB it's also everything you couldpossibly get, other hardware IDs are unaccessible under DOS and require special programming) Two lines of PHP parsing and voila, you've your value. if this is a suitable solution for you (ie, you're not on *nix), I'm ok to code it ind etails. Just tell. |
|||
| By: guydeschepper | Date: 10/04/2003 05:06:00 | Type : Comment |
|
| yep, I know this only works on the server (of course) ;-) I was "afraid" already it is only possible by using the underlying system. Yes, I am indeed using windows as the server's OS. As you suggested, can you please give me the details on how to parse this system call from within PHP ? as I am just starting with PHP programming, I don't know that much of it yet ;-) thanx ! |
|||
| By: VGR | Date: 10/04/2003 05:36:00 | Type : Answer |
|
| -----------------script : <?php // // getvolumeID.php : get any volumeID // //VGR10042003 // $drive='C:'; // adapt to your needs // prepare command $syscmd="dir $drive"; // execute, get results $fp=popen($syscmd,'r'); if ($fp) { // ok // read $continue=TRUE; while ((!feof ($fp))and $continue) { $buffer = fgets($fp, 4096); $continue=(strpos($buffer,'-')===FALSE); // the volumeID is the first that may contain a dash } // close pclose($fp); // extract information $expl=explode(' ',$buffer); $poubStr=$expl[count($expl)-1]; // display echo "the Volume ID of $drive is $poubStr "; } else echo "the command '$syscmd' could not be executed"; //end ?> ------- result : the Volume ID of C: is 5C40-328D |
|||
| By: guydeschepper | Date: 10/04/2003 05:46:00 | Type : Comment |
|
| Thanx ! Just tried it, and it really works ;-) I'll accept your answer right now. Guy |
|||
| By: VGR | Date: 10/04/2003 05:55:00 | Type : Comment |
|
| huh yes, it works 8-) Usually, I test what I post 8-) Beware, I used the dash to stop parsing the command (because of languages differences in the rest of the text) : couldn't use 'volume' (occurs twice, althought I could have cope with this situation), nor French words, so I used the dash. This means that is a volume NAME (drive's NAME) co,ntains a dash, my script wxill fail to get the VolumeID and will display... the name I guess |
|||
| By: guydeschepper | Date: 10/04/2003 18:00:00 | Type : Comment |
|
| yeah, I noticed that, but I guess that's no problem for me. thanx again. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








