Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 12th, 2007, 8:48 AM   #1
davil
Newbie
 
Join Date: Nov 2007
Posts: 26
Rep Power: 0 davil is on a distinguished road
Question regarding data input into PHP/Mysql using something other than GET

Hi all,

This is kinda more of a general question than simply a PHP question... I'm fairly decent at PHP and BASIC (I use Freebasic to make simple .exe console apps)
I'm struggling at learning C or C++ - basic just works whereas there are different header files with every tutorial / compiler I get so I'm getting a bit lost.
I haven't had any formal programming training yet so please bear with my stupidity.

Anyway, I have a PHP/MySQL based database system here at work that logs all PC info into the database, in this kind of format to give you an idea:

sql Syntax (Toggle Plain Text)
  1. DROP TABLE IF EXISTS `aidahardware`;
  2. CREATE TABLE `aidahardware` (
  3. `id` int(11) NOT NULL AUTO_INCREMENT,
  4. `datestamp` date DEFAULT NULL,
  5. `timestamp` varchar(25) DEFAULT NULL,
  6. `hostname` varchar(40) DEFAULT NULL,
  7. `serial1` varchar(18) DEFAULT NULL,
  8. `serial2` varchar(18) DEFAULT NULL,
  9. `serial3` varchar(18) DEFAULT NULL,
  10. `primaryip` varchar(15) DEFAULT NULL,
  11. `primarymac` varchar(17) DEFAULT NULL,
  12. `lastuser` varchar(25) DEFAULT NULL,
  13. `make` varchar(40) DEFAULT NULL,
  14. `model` varchar(40) DEFAULT NULL,
  15. `chassis_type` varchar(20) DEFAULT NULL,
  16. `cpu_info` varchar(50) DEFAULT NULL,
  17. `cpu_info2` varchar(50) DEFAULT NULL,
  18. `hdd` varchar(300) DEFAULT NULL,
  19. `optical` varchar(250) DEFAULT NULL,
  20. `ram` int(10) DEFAULT NULL,
  21. `os` varchar(35) DEFAULT NULL,
  22. `sp` varchar(20) DEFAULT NULL,
  23. `iever` varchar(30) DEFAULT NULL,
  24. `av` varchar(35) DEFAULT NULL,
  25. `avver` varchar(35) DEFAULT NULL,
  26. `avdat` varchar(10) DEFAULT NULL,
  27. `monitor` varchar(35) DEFAULT NULL,
  28. `chipset` varchar(35) DEFAULT NULL,
  29. `audio` varchar(65) DEFAULT NULL,
  30. `currproxy` varchar(20) DEFAULT NULL,
  31. `lanproxy` varchar(20) DEFAULT NULL,
  32. PRIMARY KEY (`id`)
  33. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  34.  
  35. INSERT INTO `aidahardware` VALUES ('','2007-10-22', '10:29', 'thehostname', 'theserial1', 'theserial2', 'theserial3', '10.175.52.10', '00-14-38-my-mac', 'the username', 'Hewlett-Packard', 'HP Compaq nx8220 (PG802EA#ABU)', 'Notebook', 'Mobile Unknown; 1551 MHz (7.5 x 207)', 'Intel(R) Pentium(R) M processor ', 'C: (NTFS);8172 MB (1277 MB free)£D: (NTFS);49051 MB (47799 MB free)£', 'MATSHITA UJ-822Da£', '512 MB', 'Microsoft Windows XP Professional', 'Service Pack 2', '6.0.2900.2180', 'McAfee VirusScan Enterprise', '8.0.0.912', '2007-09-20', 'Plug and Play Monitor [NoDB]', 'Unknown', 'Intel 82801FB ICH6 - AC97 Audio Controller£', '10.100.1.14:80', '10.100.1.14:80');
  36. etc. etc. etc.

as you may have guessed each machine runs AIDA32 in their logon script, which is the old freeware version of Lavalys Everest and it reports all the hardware info back to CSV files I have on a NAS server...
Every now and then I run a Freebasic EXE that converts all the data in the CSV files into a workable .sql file that I import into my server. (I know how bad of a practice this is but we're very busy here and I find it hard to find the time to learn new languages etc.)
Also as you can see I split certain fields like 'hdd' into sepearate parts using a seperator like £ and/or ; - if you check the SQL above you'll see what I mean. Then I could explode that info into an array for easier use in my PHP. That works a charm currently.

Ok so that's the way it currently works and I have a web-based interface so everybody here in our I.T. department can search for info by pc, or by hostname or by whatever. I have built up many handy SQL queries from the info and even a custom SQL query page so they can do custom queries on the info. We deal with just over 600 PCs in the building so nothing too crazy.
I thought that I should change it to make it dynamic so I don't have to run the exe or schedule it to run but instead, every time a PC logs on it reports directly back to the web server using the console version of curl or whatever.

My latest work on this involved this sort of code

php Syntax (Toggle Plain Text)
  1. $data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
  2.  
  3. $datestamp = $data[1];
  4. $timestamp = $data[2];
  5. $hostname = $data[3];
  6. $serial1 = $data[4];
  7. $serial2 = $data[5];
  8. $serial3 = $data[6];
  9. $primaryip = $data[7];
  10. $primarymac = $data[8];
  11. $lastuser = $data[9];
  12. $make = $data[10];
  13. $model = $data[11];
  14. $chassis_type = $data[12];
  15. $cpu_info = $data[13];
  16. $cpu_info2 = $data[14];
  17. $hdd = $data[15];
  18. $optical = $data[16];
  19. $ram = $data[17];
  20. $os = $data[18];
  21. $sp = $data[19];
  22. $iever = $data[20];
  23. $av = $data[21];
  24. $avver = $data[22];
  25. $avdat = $data[23];
  26. $monitor = $data[24];
  27. $chipset = $data[25];
  28. $audio = $data[26];
  29. $cproxy = $data[27];
  30. $lproxy = $data[28];

and using
curl -0 http://mylocalwebserver/newinfo/date...o/hostnameinfo etc etc. etc.

But as you remember from the SQL before I would be passing a fair amount of data and also there are some strange characters in the data so I'm wondering if there's a more effective / efficient way to get this data from AIDA .csv form to the server itself?
The reason I'm not using ODBC on the clients is because we have a mixed environment with NT/2k/XP machines and I prefer to stick to what I know works, like AIDA for example works on all three platforms as does good old freebasic executables and text files (CSV) etc.

So to reiterate my question I'm wondering should I have the text files go to the web server and run some command line PHP that puts the data into the MySql server or maybe even an ODBC link on the server that a Freebasic or simple C++ program that loops and takes each new text file in and puts the info directly into the MySql server and then deletes the text files when it's done. Or should I stick with curl and work out my character problems by using simpler characters?
I just get the feeling that passing all the data through the URL is bad practice. I had also considered there may be a way to bypass curl and send the data using some sort of C++ program using POST rather than GET...

Also I was wondering how simple would it be to write a C++ or C program to extract the info from the BIOS (the info I'm currently using AIDA32 for)

I know it's a lot of questions and I probably have most of this wrong but I'm looking for how a real programmer would do this as I usally fart out some basic+php and meld it all together with sticky tape and hope for the best :-D

Thanks for reading all this....
davil is offline   Reply With Quote
Old Nov 12th, 2007, 9:58 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

You might want to have a look at something like this. Some applicable quotes:
Quote:
SysInfoTM is a system and storage solution for asset inventory and configuration reporting for most major Linux, UNIX, Apple Macintosh, and Microsoft Windows platforms as well as leading NAS and SAN Storage Systems and logical volume software solutions. SysInfo provides extremely detailed system hardware, software, OS configuration, and storage asset management and configuration data in multiple platform agnostic formats.

Data can be retrieved from the local system or remotely over any TCP/IP network from any system with the SysInfo Agent (installed by default as part of the SysInfo product) installed.
Quote:
SysInfo is easy to embed in your own program or shell script using our shell or Perl API's. Our parsable output encoding provides a field deliminated format which is easy to parse and convert into your own format or feed into a database.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 12th, 2007, 10:09 AM   #3
davil
Newbie
 
Join Date: Nov 2007
Posts: 26
Rep Power: 0 davil is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

Thanks for that... looks very good.. except for the fact that it costs money and we are just one building of many around the country (Ireland) and in order for us to buy software there would be a lot of red tape etc. etc.... also this is a learning exercise for me so I'm just wondering how somebody would do this with only PHP and BASIC or PHP and C/C++ if you had no other choice...
davil is offline   Reply With Quote
Old Nov 12th, 2007, 11:12 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

The cost per machine for that is relatively trivial. If I were in your position, I'd investigate it thoroughly. If it wasn't sufficient, or circumstances prevented me using a third party product, or I had no choice, then I'd solve the problem on my own, even though I'd be reinventing the wheel.

I don't believe your problem is getting system information. There are dozens of things that do that, and code snippets all over the web explaining the process. Platform agnosticism complicates the problem, of course. I also don't believe your problem is getting the information into the database. You are, in fact, already doing all that in a roundabout way.

So let's investigate your "How would I improve this" question. There is, for instance, a program that gets system information and presents it in a HTML form. You could write one of those. The form goes to the server via POST. Your server-side code (PHP, C++, whatever) picks that up, massages any fields you like to modify (split up, combine, reformat, whatever), and sticks that into the database.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 12th, 2007, 12:15 PM   #5
davil
Newbie
 
Join Date: Nov 2007
Posts: 26
Rep Power: 0 davil is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

Ok... I think I get you. I'll look into HTML forms more closely as the PHP side of it is no problem to me. and then I can use POST instead of GET... I also wanted that for security reasons. I might include PHP sessions and MD5 or SHA1 encryption too.. (not too sure if the sessions bit is needed but u get the idea). But then only if I'm not too lazy :-D thanks again for your help I'll reply again when I get it done.
davil is offline   Reply With Quote
Old Nov 20th, 2007, 6:58 AM   #6
davil
Newbie
 
Join Date: Nov 2007
Posts: 26
Rep Power: 0 davil is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

Ok so I'm getting into this and it seems to be working fine but I'm having problems with the foreach command...

When I get the info from a MySQL database I usually use the following command to assign a variable to each value:

php Syntax (Toggle Plain Text)
  1. foreach ($row as $key => $value) {$$key = $value;}
This works perfectly but I was wondering is there a way to check something like $datestamp vs $new_datestamp by doing this?

php Syntax (Toggle Plain Text)
  1. foreach ($row as $key => $value) {
  2. $$key = $value;
  3. if ($new_$$key==$$key){echo "$new_$$key is same as old $$key, which is $value\n";
  4. }
I know this doesn't work above but I'm presuming it's something to do with my syntax... I've had a look at PHP.net tutorials and done a bit of googling but I'm lost on this simplest of all problems...

I could do it the long way with like 20 conditions but I want to get more efficient in my programming.
davil is offline   Reply With Quote
Old Nov 20th, 2007, 8:06 AM   #7
davil
Newbie
 
Join Date: Nov 2007
Posts: 26
Rep Power: 0 davil is on a distinguished road
Re: Question regarding data input into PHP/Mysql using something other than GET

I've started a new thread for this (sorry I had hoped to remove the above post but I must be out of time) anyhow the new thread is here:

http://www.programmingforums.org/post137196.html
davil is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data getting question quantalfred Coder's Corner Lounge 8 Jul 22nd, 2006 2:39 AM
how do i automate text data and input into database? lionel84 C# 0 Jun 26th, 2005 9:35 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC