fender967 Posted February 10, 2009 Share Posted February 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/ Share on other sites More sharing options...
php.ajax.coder Posted February 10, 2009 Share Posted February 10, 2009 This code displays the page the user has come from //Where the user has come from $from = $_SERVER['HTTP_REFERER']; // the viewers refer url Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759029 Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759031 Share on other sites More sharing options...
fender967 Posted February 10, 2009 Author Share Posted February 10, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759034 Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 header would be a good redirect. As far as why are you adding cat to that, it is not needed, unless a link is going to be under multiple categories. Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759037 Share on other sites More sharing options...
fender967 Posted February 10, 2009 Author Share Posted February 10, 2009 Each link will be under one of 7 categories and there will be several different links in each category. Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759040 Share on other sites More sharing options...
fender967 Posted February 11, 2009 Author Share Posted February 11, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759424 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Post your code. You have output before the header call. Simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/144651-how-can-i-count-pageviews-and-display-on-another-page/#findComment-759673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.