Solved

How to gather statistics: PHP, session ID

Posted on 2006-06-26
6
508 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
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 14

Author Comment

by:top_rung
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks so much.  Increased points!  

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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:
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

10 Experts available now in Live!

Get 1:1 Help Now