Solved

How to gather statistics: PHP, session ID

Posted on 2006-06-26
6
516 Views
Last Modified: 2008-02-01
Windows server 2003, MySQL, PHP, IIS

Is there a tool that will allow for the tracking of the ID# of dynamic pages (Ex. "index.php?id=2754")?


thanks.




0
Comment
Question by:top_rung
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jmar_click
ID: 16988559
Are you trying to see what pages get hit more often? If so, then You can create a log table. Then create a function that inserts into the log table the name of the file you are in.

Here it is in pseudo code
function append2log(fileName){
receive file name
insert file name into log table

insert fields(IP, fileName, DayofWeek, Anything_Else_You_Deem_Neccesary)
}

Just call the function at the top of your pages, if you're using includes, then you only have to include it in your header.

There is also webmin
http://www.webmin.com/
0
 
LVL 14

Author Comment

by:top_rung
ID: 16992995
Thanks, for your reply. here is more detail...

A client has a site that provides a web service for many individual customer's - essentially they will each have their own site. From the Index page. the users login and are taken to their respective account. once in the account, they have a list of items that belongs to them.  If they click and item, it takes them to a detailed view of that item.  The item is the ID that I need to track for each user.  I need to see the statistics for each item.

I hope that makes sense.

Here is the url path during usage...

www.domain.com> (user logs-in) www.domain.com/iua/welcome.php> (user accesses an Item)www.domain.com/iua/index3.php?id=8489


0
 
LVL 3

Expert Comment

by:jmar_click
ID: 16993796
I understand your process a bit more now. You can use an intermideate page before the user gets taken to the item detail page. The new page just logs the item id then redirects to the item detail page.

www.domain.com> (user logs-in) www.domain.com/iua/welcome.php> (user accesses an Item)>(New page)logItemID.php?url=www.domain.com/iua/index3.php&id=8489

So basically instaed of the last link being pointed to the item detail page, it points to a new page and you pass the url of the item detail page and the id as URL varaibles.

The new page takes the ID and logs it into your log table (same process as in my previous post would still work here I think)

Then you redirect to the URL you passed to the new page.

-----------------------------------------------------------------
Another method would be to write a function that takes the ID and records an entry into your log table. You'd place this function at the top of every page you want to track. Something like:

pseudo code
function append2log(ID){
receive ID
insert ID into log table

insert fields(IP, ID, DayofWeek, Anything_Else_You_Deem_Neccesary)
}

I hope I explained that properly.

Would something like that achieve what you are trying to do?

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 14

Author Comment

by:top_rung
ID: 17005209
Sounds logical; I think both ideas would accomplish it.

Not being the web developer, can you give me a quick run down of how to apply the code? Just a generic understanding would be appreciated... like written in what, placed where, etc.

Thanks for your help
0
 
LVL 8

Accepted Solution

by:
RWJDCom earned 350 total points
ID: 17006935
I always write my code right on the server in vi or pico (easier editor) or you could download the php files to your local computer and edit them in something like Zend Studio or even notepad.  All you would need to do is create a db connection and then insert the data.  I personally would write a function to do it, I use a DB connection function that works great for everything and makes it real easy to add new functions.  Here is what I would do...

First create a file called logging.inc.php and put the following code into it...
<?php

   $db_host = localhost;
   $db_login = "your_db_login";
   $db_passwd = "your_password";
   $db_name = "db_name";

   $connection = mysql_connect($db_host, $db_login, $db_passwd);
   mysql_select_db($db_name);

   $dbh[con] = $connection;

   function database_mysql_query(&$dbh, $query)
   {
      $dbh[ok] = 0;
      $dbh[result] = 0;
      $dbh[error] = "None";
      $dbh[query] = $query;

      $result = @mysql_query($query, $dbh[con]);
      if ($result)
      {
         $dbh[result] = $result;
         $dbh[ok] = 1;
         $dbh[error] = "None";
      }
      else
      {
         $dbh[result] = 0;
         $dbh[ok] = 0;
         $dbh[error] = mysql_error();
      }
   }

   function database_mysql_fetchrow(&$dbh)
   {
      $result = @mysql_fetch_array($dbh[result]);
      return $result;
   }

   function database_mysql_insertid(&$dbh)
   {
      $id = mysql_insert_id();
      return $id;
   }

   function database_mysql_nresults(&$dbh)
   {
      $total = mysql_num_rows($dbh[result]);
      return $total;
   }

   function LogID(&$dbh, $id)
   {
      if (!$id)
         return false;

      $now = time();
      $query = "INSERT INTO logs VALUES($now, $id)";
      database_mysql_query($dbh, $query);

      if ($dbh[ok])
         return true;
      return false;
   }
?>

You will need to create a table called logs with now as a 10 char interger and pageid as a 10 char varchar so that the data can be logged to the database.  Then you will need to include the logging.inc.php file in any page you want to log the id's from and call the logging function like so...

include_once("logging.inc.php");
LogID($dbh, $_GET['id']);

That will log everything to the database, then when you want to get all of the data you can just run a SELECT * FROM logs and your good to go.

I hope this helps.  If you have any questions please let me know.
0
 
LVL 14

Author Comment

by:top_rung
ID: 17009369
Thanks so much.  Increased points!  

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
how to get responsive video to always be centered 15 65
modify h2 4 89
What language/protocol is the Angular Chat? 2 58
Angular 2 - Issue in page Layout 2 48
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

20 Experts available now in Live!

Get 1:1 Help Now