TIP: Using PHP include and JavaScript together

17 views
Skip to first unread message

Tekl

unread,
Jan 22, 2010, 5:48:53 PM1/22/10
to SlimStat
Hi,

I found a way how to track all users. It doesn’t matter if they have
JavaScript enabled or not.

Here the code:

<script type="text/javascript" src="/slimstat/?js"></script>
<noscript><img src="/slimstat/stats_js.php?ref=<?=urlencode($_SERVER
['REQUEST_URI'])?>&amp;url=<?=urlencode($_SERVER['REQUEST_URI'])?
>&amp;res=&amp;ttl=<?=urlencode($title)?>"
style="position:absolute;top:-100px;left:0"></noscript>

If you don’t want to track the title just remove urlencode($title) but
leave ttl= empty. If you have no generated title you could replace
your normal <title> tag with this:

<title><?=$title='My interesting Super Homepage'?></title>

It’s a short form of <?php $title='bla'; echo $title; ?>

Well, the JavaScript solution just adds an invisible image to the
document and that’s what we do inside the noscript.

I haven’t tested if every Browser ignores and not only hides content
in the noscript.

Okay, you can’t really track all users. When they have images disabled
or use a text browser, they are not tracked with this solution.

Tekl

Tekl

unread,
Jan 22, 2010, 5:51:08 PM1/22/10
to SlimStat
Sorry,

you should replace the first REQUEST_URI with HTTP_REFERER

Tekl

Tekl

unread,
Jan 22, 2010, 6:27:35 PM1/22/10
to SlimStat
As stats_js.php uses rawurldecode you should replace urlencode with
rawurlencode.

<script type="text/javascript" src="/slimstat/?js"></script>
<noscript>

<img src="/slimstat/stats_js.php?ref=<?=rawurlencode($_SERVER
['HTTP_REFERER'])?>&amp;url=<?=rawurlencode($_SERVER['REQUEST_URI'])?
>&amp;res=&amp;ttl=<?=rawurlencode($title)?>"

Reply all
Reply to author
Forward
0 new messages