PhpMyVisites XHTML compatible?

PhpMyVisites is a statistics script which I decided to try using because they said that it was XHTML compatible. I guess they meant that it worked with XHTML served as text/html or maybe I did something wrong? Unfortunately, after I set it up and included the code, I found problems in Mozilla (at that time I was serving as text/xml, and now application/xhtml+xml). It just wouldn’t log the visits.

I therefore tried to find what the problem was, and I have come up with a solution. I give no guaranty that it will work for all cases, or that it solves all problems. In fact I’m not even sure whether all I did was required to fix the problem, but I shall post everything I did here.

First thing, open up the “phpmyvisites.php” file in your favourite text editor (I’m using Notepad2). Using the find&replace tool, subsitute <b> with <strong>, </b> with </strong>, and <br> with <br />. That should make the tags correct now.

Next, open up “phpmyvisites.js”. Look for the last line “doc.writeln(‘<img src=”‘+src+’&ref=’+escape(top.document.referrer)+'” alt=”phpMyVisites” style=”border:0″ />’);“. Now, I’m not entirely sure what this “doc.writeln” is, but I don’t think it works. At least it doesn’t seem to work. Erase off that line and put the following lines in :

var a = document.getElementsByTagName(“a”);
for(var pos = 0; pos < a.length; pos++){
if(a[pos].getAttribute(“href”) == “http://www.phpmyvisites.net/”){

var write=document.createElement(‘img’);
write.setAttribute(“src”, src);
write.setAttribute(“alt”, “phpMyVisites”);
document.getElementsByTagName(“a”)[pos].appendChild(write);
}
}

This is the code you can use to include in your pages :

<!–– phpmyvisites ––>
<a href=”http://www.phpmyvisites.net/” title=”phpMyVisites : an open source website statistics application in PHP/MySQL, distributed under the GPL.” onclick=”window.open(this.href);return(false);”>
<script type=”text/javascript”>
// < ![CDATA[
var phpmyvisitesSite = 1;
var phpmyvisitesURL = “http://yoursite.com/phpmyvisites/phpmyvisites.php”;
// ]]>
</script>
<script type=”text/javascript” src=”http://yoursite.com/phpmyvisites/phpmyvisites.js”></script>
</a>
<!–– /phpmyvisites ––>

I actually removed the ‘noscript’ part for the time being.

Anyway, I’m no Javascript expert. So, if I do make mistakes, it would be nice to tell me. It’s just that I didn’t manage to find this solution anywhere else.

Have fun!

Leave a Reply

Spam, shameless advertising and comments which do not contibute to the value of the post may be deleted!