Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to gather statistics: PHP, session ID

Posted on 2006-06-26
6
Medium Priority
?
540 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

783 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