Solved

How to gather statistics: PHP, session ID

Posted on 2006-06-26
6
525 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
Independent Software Vendors: 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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best environment for cross platform web development? 5 71
youtube blocking politics 4 79
Error in Angular 2 when showing in grid 4 45
Display field if column exists 7 33
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

749 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