Solved

Reading Hard Drive Serial Number using PHP

Posted on 2008-06-10
9
4,087 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MySQL database data submission 7 39
Creating a slider 12 34
writting html or javascript in PHP 8 10
Adding through query php 9 8
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

708 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

19 Experts available now in Live!

Get 1:1 Help Now