Jump to content

How Can I Count Pageviews and Display on Another Page?


fender967

Recommended Posts

Here is the problem I need to solve.. I have several links out from my index page and I need to track how many times visitors have clicked those links, then display that number on my index page by the link.

 

I am thinking that the easiest way to track the hits out is to send the link to a page on my site which redirects to the page I want the link to go to.  The part that I don't know how to do is keeping count of how many times that has happened, and then printing that number/variable back on my index page.

 

I'm still learning php and any help with this would be greatly appreciated.

You will either need to use files (not recommend) or a MySQL database (recommended).

 

For files look into: fopen, fwrite and fclose.

 

The script you create will be something like "linkout.php" then the links on the page would be "linkout.php?id=4" etc.

Ok so say my link is linkout.php?cat=3&item=5

 

My php on the linkout.php would do something like ++ to the variable in the mySQL database equal to catagory 3 item 5.

 

My index page would echo the variable for cat 3 item 5.

 

Does that sound right?

 

Also, what is the most accepted form of redirect?

I am having trouble with this; I can't redirect the page with header('location:') because it is saying Warning: Cannot modify header information - headers already sent by X in Y.php on line 6

 

Is there a way to redirect after I insert the data into the database?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.