View Full Version : PHP and Statcounter
POB/London
10-24-2004, 08:21 PM
Hello!
My website is www.PM-04.com
My username is lmiller
I have just migrated all of the photo galleries (example: http://www.pm-04.com/galleries/tunisia_7.html) onto a different part of my server, and I have started to use a set of PHP scripts to disply images.
The freeware product I have used is called Gallery (www.pm-04.com/gallery).
Is there anyway I can include the statcounter code in the PHP (ie on the gallery header page?) I have temporarily set up a portal page here (www.pm-04.com/gallery_portal.html) but it's not really good enough because some people go straight in by typing the URL...
Any suggestions / workarounds would be ace.
Fantastic product, by the way. I have recommended you to all of my webmaster friends. :)
webado
10-25-2004, 02:47 AM
I dont' know exactly how you'd do it in Gallery, but in all PHP applications where I've included the Statcounter code I've tried to find either the html template or the php footer segment. If you have an html template, then it's easy, find the </body> tag and insert the counter just above, centered or whatever.
If you have a php footer segment that you can isolate and customize (I usually look for wherever the software copyright stuff goes), then find the place where you want to insert the code and add it like this:
echo '';
echo '<script type="text/javascript" language="javascript">';
echo 'var sc_project=357167;';
echo 'var sc_partition=1;';
echo '</script>';
echo '<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js">';
echo '</script>';
echo '<noscript><a href="http://www.statcounter.com" target="_blank">';
echo 'http://c2.statcounter.com/counter.php?sc_project=999999&java=0';
echo '</a></noscript>';
echo '';
echo '</center>';
Basically what you do is take each line of code generated by Install Code and enclose it in echo ' and '; .
Pay attention not to break lines that may be generated as one long line.
Use Notepad to create this php code and then copy & paste it into the php script where you want it.
Don't copy my code as is, since it will not have your correct settings. Get your code and transform it into php in this manner.
paulop
11-18-2004, 08:13 AM
If you put the Statcounter code into a PHP footer that is loaded for every page, does this affect the way the stats operate in any way? I converted my site to PHP pages with the code in a footer, and I noticed that the number of unique visitors has risen dramatically, but the number of page loads hasn't increased much. I can't see where the extra unique visitors are coming from in any of the other stats, so I'm wondering if this could be the reason, or is it just a coincidence and there is really a different reason (e.g. visitors disabling cookies)?
webado
11-18-2004, 01:50 PM
If you put the Statcounter code into a PHP footer that is loaded for every page, does this affect the way the stats operate in any way? I converted my site to PHP pages with the code in a footer, and I noticed that the number of unique visitors has risen dramatically, but the number of page loads hasn't increased much. I can't see where the extra unique visitors are coming from in any of the other stats, so I'm wondering if this could be the reason, or is it just a coincidence and there is really a different reason (e.g. visitors disabling cookies)?
I can't compare as I don't have a "before" and "after" scenario.
I'd say with the code in a footer that appears on every page that is displayed, you would be logging more hits than before over the same period of time. I wouldn't know about why your number of hits is about the same, yet unique visitors would be lots higher that would be explained by using it in a php footer. Yes, cookies disabled may do this.
You can verify the individual logs though and see if it supports this theory.
paulop
11-18-2004, 04:11 PM
I had the Statcounter code on every page before (i.e. when it was just html pages), but then reorganised my pages to use header and footer templates using PHP. So in theory, each server request should be generating the same HTML pages as before and therefore the stats should be no different. However, I wondered if I'm being too simplistic and that by moving the Statcounter code into single footer template it is somehow interpreting 10 page loads on different pages as a 10 unique users (rather than 10 different page loads by the same user).
I'm not convinced I'm right, but it seems a possibility. I'll keep monitoring the stats for evidence either way, but if you know of a more substantive answer one way or the other I'd be interested to know.
webado
11-18-2004, 05:00 PM
Sorry, I don't know. I haven't seen this bahaviour myself and I use the counter code in some places in the html template footer section (i.e. in an IPB forum) and in others in a php script that builds a page, in a php footer portion (in a Coppermine gallery). I can normally account for all the pageloads I see.
The only strange pageloads are when I test an html paeg from my own computer and then, for some strange reason I get 2 pageloads being logged: one with an unknown screen resolution and no referrer (as if I had javascript disabled), and another with full details. I have posted about this before but it got lost in the shuffle I guess.
motorwatchercounter
11-18-2004, 09:42 PM
Hi paulop,
I have the Statcounter on a PHP template footer still in development. Each time the content changes (not the footer content) it record a differnt page.
Benefits: you can see what pages are being run through without the code on each page.
Against: It will eat you page limits.
webado
11-18-2004, 09:57 PM
Hi paulop,
I have the Statcounter on a PHP template footer still in development. Each time the content changes (not the footer content) it record a differnt page.
Benefits: you can see what pages are being run through without the code on each page.
Against: It will eat you page limits.
Well, if you want to track each page, then this is the way.
paulop
11-20-2004, 10:14 AM
Hi paulop,
I have the Statcounter on a PHP template footer still in development. Each time the content changes (not the footer content) it record a differnt page.
Benefits: you can see what pages are being run through without the code on each page.
Against: It will eat you page limits.
Thanks motorwatchercounter,
When do you think the PHP template footer code will be ready? What is the current behaviour of the code on a PHP footer? Am I right about 1 person viewing 10 pages will show up as 10 unique users rather than 10 pageloads by 1 user?
motorwatchercounter
11-20-2004, 02:35 PM
Hi paulop,
Firstly let me make it clear I am just a forum member, not anything else.
The development part was for code I am using on my development site, not Statcounter.
You can use the code as it is on the footer right now. It will show as the same person viewing pages so you should be able to tell when pages have been viewed (and therefore the content people are looking for) by the returned page. 10 refreshed pages with the footer will be 10 counts.
This bit of code may help;
<table border="0" width="100%" bgcolor="#A9B8D1" cellspacing="0" cellpadding="0">
<tr><td width="100%" height="1">%URL%/layout_images/spacerbig.gif</td></tr></table>
<p align="center" /> <a href="javascript:openPage('templates/terms.html')">Terms
of Use</a> - About Us (javascript:openPage('templates/aboutus.html'))
- Trade advertising (javascript:openPage('templates/advertise.html'))
- Help (javascript:openPage('templates/help.html'))
<script type="text/javascript" language="javascript">
var sc_project=xxxxxx;
var sc_partition=1;
</script>
<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript>http://c2.statcounter.com/counter.php?sc_project=xxxxxx&java=0 (http://www.statcounter.com/free_hit_counter.html) </noscript>
</body>
</html>
webado
11-20-2004, 03:10 PM
I think you're misreading Motorwatchercounter. It's HIS own web development, not Statcounter's, that he's talking about.
There's no PHP template footer in development by Statcounter.
Statcounter code can be inserted into PHP code by the sticking to the rules of PHP, i.e. you use the PHP echo command to write out the Statcounter code lines. For Statcounter code to function it must remain intact as it is served and rendered as HMTL. ---EDIT --- Or you use within PHP the HTML code shown by Motorwatchercounter above, as a template :)
Whether the visitors show up as unique or not depends on other factors, not on whether to code is placed on an HTML page or on a PHP page. Regardless of what coding language is being used to code the page in, the visible source code of a page which is rendered by the browser is ultimately HTML.
Visitors are placed into 2 categories: first time visitors and returning visitors. This is determined by the presence or absence of a cookie that Statcounter code will have placed on the user's computer on a first visit, and consulted on subsequent visits. So when the cookie is created, this is a new (i.e. first time) visitor. If the cookie is already there, this a returning visitor now.
Unique visitors are at any given moment those who are first-time visitors plus those that are returning visitors.
For pageloads done by a user whose browser does not accept cookies (or who has deleted them since the last pageload), every time that user will be considered a first time visitor, since no cookie is there to indicate a prior visit. Thus this first time visitor will be tallied into the unique visitors count.
And now before you ask why it's not determined instead by whether the IP address has been logged before or not, here is the main reason why this would be no more accurate: IP addresses may and often do change very frequently, sometimes even during the same visit of a user from one pageload to another (e.g. AOL users).
Because IP addresses often change, the IP address that a visitor had during one visit may be shown by a totally different visitor at another time, if they have the same ISP. Even if it is unlikely to really be a different visitor, it's not 100% certain that it is not, so the assumption will not result in more accurate results.
Consider a network in a college. All the computers on that network will have the same IP address at a given moment. Behind each computer there are different users. If you consider all pageloads from the same IP address as having come from the same visitor this may not be correct if more than one computer is being used to visit the same site. The presence or absence of the cookie will sort all this out - as long as cookies are enabled. And ultimately this is the crux of the problem.
Another reason why you cannot just lookup the IP address among the other IP addresses logged is the log size itself. You can only conclude that a given Ip address has visited or not if it si present in the log. The larger the log, the more chance you have of perhaps finding it there if it has visited before. But if you don't find it, you'll never know if it has done so or not during pageloads that have fallen off the log.
motorwatchercounter
11-20-2004, 03:14 PM
Wow. I wish I had said that :wink:
Positioning the Statcounter code in the html part means you do not need to use the echo command.
webado
11-20-2004, 03:28 PM
Wow. I wish I had said that :wink:
Positioning the Statcounter code in the html part means you do not need to use the echo command.
Ouch, that's true :) But when I first did it I didn't know you could add a body of html code inside a php script :oops: I set mine up as a separate php script and I include it into other php scripts using the REQUIRE construct. I'll have to see if the file I REQUIRE can be set up as HTML code with a PHP extension. Probably yes.:)
paulop
11-21-2004, 09:19 AM
Thanks guys for the clarifications. I've ultimately concluded that my Statcounter code is working correctly in my PHP footer. The strange stats I first observed seem to have stopped, so it must have been something else that caused them. :)
motorwatchercounter
11-21-2004, 12:14 PM
Hi Paulop,
Just a comment on the news on your index page and the news page. Try and use a news script with a "more news" link which will go to the news page.
Have a look at the following site;
http://www.interlogy.com/products/content/article/index.html
There are plenty of these scripts around but you may find using a script something like this will make the site easier to maintain.
Oh yes, it's a freebee also.
paulop
11-22-2004, 10:21 PM
Thanks motorwatcher, I've had a look at the site, and will take a look at using the scripts.
A3M0N
12-06-2004, 05:40 PM
can you have your statcounter code be in a file called somthing like, cnt.php - then in your include that file using php? like this:
<?php include(cnt.php) ?>
or will that jack up your stats?
thanks!
later
A3M0N
12-13-2004, 01:20 PM
hello?
webado
12-13-2004, 02:15 PM
Yes, you can put it in that way, and it won't jack up your stats depending on where you are including it, of course. The counter logs and increments every time it is executed, simple as that.
motorwatchercounter
12-18-2004, 11:34 AM
can you have your statcounter code be in a file called somthing like, cnt.php - then in your include that file using php? like this:
<?php include(cnt.php) ?>
That is a superb idea, especially for templates. It may restrict your HTML pages but you can always open on HTML and put an onload command in to jump to the PHP version.
juglesh
02-04-2005, 09:03 PM
i am just using an include on my pages.
<?php include"statcounter.php"; ?>
inside statcounter.php is just my counter code, nothing more or less.
the thing to do if you are using a 'template' php page is at your stats, uncheck the 'chop url'. then you can see where your visitors are going in your page. so, for me, i have something like this:
webpage.php?content=contact
webpage.php?content=links
webpage.php?content=aboutus
webpage.php?content=sitemap
with hit counts for each. so i can see which "page' my vistors are going to.
thanks, statcounter!
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.