Solved

Reading Hard Drive Serial Number using PHP

Posted on 2008-06-10
9
4,124 Views
Last Modified: 2013-12-13
I am unable to run the below command in PHP file, by browsing the URL http://localhost/hddinfo.php, the status is 25, output array is empty.

exec ("hdparm -i /dev/hda", $output, $status);

But same will execute from Linux command line and shows output: php hddinfo.php

My requirement is to get the Hard Disk Serial Number on Linux box through my PHP code.

Quick help is much appriciated
0
Comment
Question by:uvals
  • 4
  • 3
9 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 21750335
try using the complete path to hdparam. I guess you run it on command line as root, but vi webserver it runs as wwwrun which has no permissions to access those information. The infromation are only accessable by root.
exec ("/sbin/hdparm -i /dev/hda", $output, $status);
0
 
LVL 24

Expert Comment

by:glcummins
ID: 21750341
When you access the hddinfo.php script via URL, you are running the script with the permission of your web server users. When you run it via the command line, you are running the script with the permissions of the account with which you are logged in. In most cases, your webserver user will not have permissions to execute commands such as hdparm for security reasons. To find out which user your webserver is running as, open your httpd.conf file and look for the line

 User <username>

where <username> is the name that Apache runs as. You can either give that user access to run hdparm (not wise on a public webserver) or find a different method to obtain the data.

Perhaps a secure method is to run a cron job that gets the data you desire and stores it in a database or file. Then your script can simply read that file, and display it as needed.
0
 
LVL 2

Author Comment

by:uvals
ID: 21791480
I tried executing exec ("/sbin/hdparm -i /dev/hda", $output, $status); It still shows me error code 25 when i execute as http://localhost/a1.php.
Also when i try running the command
hdparm -i /dev/hda >> testserialno.txt
through command line, I am unable to write into the file. How can i write the response to a file? How can I find out the serial number using exec command in PHP?

0
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 21791797
You can't get those information via webserver and using exec
hdparm is only allowed for root and not for normal users like the webserver.
run as root:
hdparm -i /dev/hda >> /tmp/testserialno.txt

and in php
echo file_get_contents('/tmp/testserialno.txt');
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:uvals
ID: 21792581
i executed hdparm -i /dev/hda >> /tmp/testserialno.txt  in command prompt. It is not writing the content into a file. i gave permission to the file too. But I am unable to write the content of hdparm into the file.
Is there any other way to read hard disk serial number in linux and display the contents using PHP?
Or How can i set a cron job to read hard disk serial number and write it into a file?
Is there a way i to read a unique serial number - may be network card #, harddisk # or processor id,etc..in linux and display the output using PHP?
0
 
LVL 2

Author Comment

by:uvals
ID: 21882610
Any answers to this... even if i read the network card id or mac address of the newtwork card is ok. i hope mac address of each network card is unique. How we do it with PHP?
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21890148
exec ("/sbin/ifconfig", $output, $status);

MAC can be easy changed on linux, it's a part of the ifconfig command
0
 
LVL 2

Author Closing Comment

by:uvals
ID: 31465687
if we modify permission to PHP file, this command may work, but if some one gives that solution it will be a complete solution to this query.

http://find.b121.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 6 26
Amazon Redshift 2 28
RELATED: How do I fix this error:  Warning: strpos(): Empty needle on line 122 11 32
phpmailer in WHILE loop - weird results 10 28
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now