Solved

Reading Hard Drive Serial Number using PHP

Posted on 2008-06-10
9
4,188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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
 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This article discusses how to create an extensible mechanism for linked drop downs.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

737 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