• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4376
  • Last Modified:

Reading Hard Drive Serial Number using PHP

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
uvals
Asked:
uvals
  • 4
  • 3
1 Solution
 
hernst42Commented:
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
 
glcumminsCommented:
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
 
uvalsAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hernst42Commented:
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
 
uvalsAuthor Commented:
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
 
uvalsAuthor Commented:
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
 
hernst42Commented:
exec ("/sbin/ifconfig", $output, $status);

MAC can be easy changed on linux, it's a part of the ifconfig command
0
 
uvalsAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now