Advertisement:

Author Topic: Hit counter for each ad  (Read 17932 times)

akapar

  • Premium
  • Full Member
  • *****
  • Posts: 152
Hit counter for each ad
« on: July 29, 2011, 12:09:04 pm »
Hi there,

I am new to PHP and HTML and need help. I would like to place a hit counter into each ad page that shows how many times the ad has been viewed. I see that number of views information is already stored at MySQL at OC_t_item_stats table.

I think a small script needs to be added to item.php at the "Modern" folder. I could not figure out how OSClass creates functions. There are many functions used in the script (e.g. osc_item_region(), osc_item_pub_date(), osc_item_description()) but I could not find where these functions are defined. I need a function to retrieve number of views information.


Some help would be really appreciated... Many thanks....

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: Hit counter for each ad
« Reply #1 on: July 29, 2011, 02:04:38 pm »
Those functions are defined in ./oc-includes/osclass/helpers/hItems.php

the functions you want is this: osc_item_views()

akapar

  • Premium
  • Full Member
  • *****
  • Posts: 152
Re: Hit counter for each ad
« Reply #2 on: July 29, 2011, 04:54:11 pm »
Thanks Ramon, you guys are great. Let me explain how to add a simple "view counter" to each ad page so that other people with little PHP knowledge can also benefit:

1) Edit \oc-centent\themes\Modern\item.php file with an editor (Notepad, Notepad++ or any other that you use to edit PHP codes)

2) Add the following code to where you would like to have the counter displayed

<div id="Item hit counter">
  <?php _e('This page has been viewed', 'modern') ; ?>
  <?php echo osc_item_views(); ?>
  <?php _e('times', 'modern') ; ?>
  <BR>&nbsp;<BR>
 </div>

3) Save and upload item.php file back to your web server.
And this is it...

potoco

  • Full Member
  • ***
  • Posts: 191
  • OSClass 3.5.3
Re: Hit counter for each ad
« Reply #3 on: July 30, 2011, 01:16:18 am »
It would be better if the counter will take only unique visits as valid...

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: Hit counter for each ad
« Reply #4 on: August 02, 2011, 01:23:34 pm »
It would be better if the counter will take only unique visits as valid...
by IP?

GazOutEast

  • Newbie
  • *
  • Posts: 13
Re: Hit counter for each ad
« Reply #5 on: August 09, 2011, 07:16:20 pm »
It would be better if the counter will take only unique visits as valid...
by IP?

you could use a PHP user-agent in the cookie then the unique is per hardware device instead of IP - most users have dynamic shared IP which could cause visitors to not get counted when they visit, whereas devices tend not to be shared as such (other than internet cafe's etc).  Also using IP then caused non-counting for zones like wifi hot spots etc.

If the user agent was set to detect something like CPU serial number and issue the cookie against that, then each machine would only be counted once against each item advert it visited ... but record tables could get pretty big however you do this.

Then again, why re-invent the wheel - there are lots of 3rd party services that could be used for this, including PEAR services on most hosting service cPanels.

SLUSA

  • Jr. Member
  • **
  • Posts: 72
Re: Hit counter for each ad
« Reply #6 on: August 10, 2011, 04:55:15 am »
The hit counter always says zero on my site.

You guys got any hit number on your site? ???

akapar

  • Premium
  • Full Member
  • *****
  • Posts: 152
Re: Hit counter for each ad
« Reply #7 on: August 10, 2011, 01:04:42 pm »
Slusa,

This is strange. It shows zero at first display of ad but at later displays the number increments. Where did you place the code? Mine is placed just after the <!-- plugins --> separator of the code (around line 100) and works fine. 

SLUSA

  • Jr. Member
  • **
  • Posts: 72
Re: Hit counter for each ad
« Reply #8 on: August 11, 2011, 01:43:17 am »
akapar,

 Thank you for your advice.

 I put the code into the same line you mentioned in item.php. The function works well.

 I wanted to use this function at "Latest Item". I did put the code into main.php but it didn't work and always zero shown.

 I appreciate your help!!

wodp

  • Newbie
  • *
  • Posts: 7
Re: Hit counter for each ad
« Reply #9 on: November 06, 2011, 09:46:33 pm »
Hello,
first thank you for great tip.

What about if we want to show Ad show counter in My account (where it shows all your ads)?

Thank you for contribution,
W.

sgx

  • Newbie
  • *
  • Posts: 1
Re: Hit counter for each ad
« Reply #10 on: November 10, 2011, 11:18:36 am »
thanks for the tip really helped

donaldpeter12

  • Newbie
  • *
  • Posts: 5
Re: Hit counter for each ad
« Reply #11 on: November 10, 2011, 03:48:18 pm »
I think a small script needs to be added to item.php at the "Modern" folder. I could not figure out how OSClass creates functions. There are many functions used in the script (e.g. osc_item_region(), osc_item_pub_date(), osc_item_description()) but I could not find where these functions are defined. I need a function to retrieve number of views information.

trains58554

  • Osclass contributor
  • Hero Member
  • *****
  • Posts: 3642
  • osCanyon, the class of Osclass
Re: Hit counter for each ad
« Reply #12 on: November 10, 2011, 05:43:14 pm »
Hi donaldpeter12

All the helper functions like osc_item_description() are stored in oc-includes/osclass/helpers

Those functions are defined in ./oc-includes/osclass/helpers/hItems.php

the functions you want is this: osc_item_views()

As Juan said you would want to use osc_item_views() that would return the number of views of that item.

Jay

thomasgreek

  • Newbie
  • *
  • Posts: 6
Re: Hit counter for each ad
« Reply #13 on: November 21, 2011, 08:40:09 am »
I am new to PHP and HTML and need help. I would like to place a hit counter into each ad page that shows how many times the ad has been viewed. I see that number of views information is already stored at MySQL at OC_t_item_stats table.

ken

  • Full Member
  • ***
  • Posts: 108
Re: Hit counter for each ad
« Reply #14 on: November 21, 2011, 10:04:43 am »
@ Thomasgreek,

If you follow akapar's second post above, you will get a hit counter in each ad. Just copy the code in step 2 and paste it where you would like it to show on the item page. 

Move the code around until you find the spot you want to place it.

Thanks,

Ken