Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » My PHP click tracking scripts 'break' BACK button RSS

My PHP click tracking scripts 'break' BACK button

This thread was started by kitenski and has been viewed 860 times, and contains 5 replies, with the last reply made by filburt1.
Post Reply
1
View kitenski's reputation
kitenski, WDF Noob Private message  
Posted July 2 '09 at 10:03 AM
      Posts: 12
Hi all,
I use some self written PHP scripts on my website, however I have just realised that if a user then clicks the back button from their browser, they go back to the tracking script, which forwards them straight back to where they came from!
Is there a way around this?
Simple example at http://www.pocketpcsoft.net, click the large FREEWARE in the tag cloud, and it calls http://www.pocketpcsoft.net/php/free....php?type=free which then redirects the user to http://www.pocketpcsoft.net/php/freeware.php
If the user then clicks BACK they end up at http://www.pocketpcsoft.net/php/free....php?type=free which then redirects the user once again to http://www.pocketpcsoft.net/php/freeware.php
the relevant snippet of freetrackcloud.php is as follows
 
$type = $_GET['type'];
$result=mysql_query( "UPDATE clickcloud SET count=count+1 WHERE name='$type'", $db);
mysql_close($db);
?>
<html>
<head>
<title><?=$type?></title>
</head>
<body>
<script>window.location.href="/php/freeware.php"</script>
</body>
</html>

Advertisement Register for free to hide these ads and participate in discussions!

2
794 points at 99% Donor Moderator Repute WDFplus Member
Posted July 2 '09 at 08:25 PM
      Posts: 11,793
Use a server-side redirect. When you have access to something like PHP, client-side redirects are mostly pointless.
header("Location: /somewhere"); 
You can't output anything before sending the header, even whitespace.
filburt1, Web Design Forums.net founder
Want to advertise on this site?
Site of the Month contest: submit your site or vote for the winner!

3
View kitenski's reputation
kitenski, WDF Noob Private message  
Posted July 3 '09 at 05:36 AM
      Posts: 12
thanks alot, that has worked. I think the reason I did the client-side redirect was to include Google Analytics tracking code into the tracking php file, as otherwise Google seems to 'loose' the fact a user clicked on my tracklink.

Is there anyway to add the Google analytics in and still use server-side redirects?

regards,

Greg

4
794 points at 99% Donor Moderator Repute WDFplus Member
Posted July 3 '09 at 12:58 PM
      Posts: 11,793
At that point, not that I know of. You could have some special (in some way) tracking code on the page that eventually redirects the user.

Google Analytics, as with all tracking programs that are client-side, are not reliable. One of our clients at work recently has gotten spikes in traffic due to what's essentially an advertising campaign. Google Analytics reported slightly lower pageviews that normal while AWStats (a server-side tracking program so always accurate) reported five times the normal number of pageviews.
filburt1, Web Design Forums.net founder
Want to advertise on this site?
Site of the Month contest: submit your site or vote for the winner!

5
View kitenski's reputation
kitenski, WDF Noob Private message  
Posted July 3 '09 at 01:01 PM
      Posts: 12
Interesting thanks. I can enable either awstats or webalizer on my domain, I know zero about either of these, any recommendations?

6
794 points at 99% Donor Moderator Repute WDFplus Member
Posted July 3 '09 at 01:06 PM
      Posts: 11,793
Webalizer is simpler but AWStats gives you more information. I prefer the latter.

Both (IIRC) generate some cache files which may count against your storage quota, so if you're low on space you might need to delete some things.
filburt1, Web Design Forums.net founder
Want to advertise on this site?
Site of the Month contest: submit your site or vote for the winner!

Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 18 Today 09:52 AM
php radio button form ketanco PHP 4 September 28 '08 12:51 PM
Need some way to page break in php and html jnunemaker PHP 1 March 9 '04 09:41 AM
PHP: Edit Multiple Items/Rows and Update Button msmith29063 PHP 0 March 2 '04 02:48 PM
Basic PHP Uploads Tutorial thexchord Coding Articles & Tutorials 2 May 2 '02 09:28 PM