6 Replies - 1762 Views - Last Post: 02 October 2011 - 06:37 AM Rate Topic: -----

#1 maria_six  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 24
  • Joined: 28-September 11

Link click tracking without database

Posted 01 October 2011 - 05:56 AM

i would to help with link click counter without database

i have these links
file.exe
file.zip

i wanna to know how many times has been clicked any links for example
file.exe - hits 150
file.zip - hits 320

can someone help me to make this thanks?
Is This A Good Question/Topic? 0
  • +

Replies To: Link click tracking without database

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 943
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Link click tracking without database

Posted 01 October 2011 - 06:10 AM

It going to be hard to track the amount of downloads without a download manager. Doing it without a database makes it a bit more tedious. What you want is to provide the user with a link like
http://www.mywebsite.com/download.php?id=1337
. The id will determine which file it is instead of passing the actual file name which could be a security issue. In your PHP script you'll use the id from the $_GET array and then fetch the file for the user. Before passing the file you'll increment the counter of that file.

Your best bet is to use a XML file to store the database. It's the most organized and there are objects within PHP to manipulate XML. My personal favourite is DOM but there's SimpleXML and many more.

A suggest structure would be something like
<?xml version="1.0"?>
<downloads>
	<file>
		<id>file_id_here</id>
		<name>File</name>
		<location>absolute location here</location>
		<size>23233</size>
		<hits>111</hits>
	</file>
</downloads>



I'd suggest making the hash of the file name and a secret key since XML files don't offer an auto increment feature for your ID. It would make it easier to add files that way.
Was This Post Helpful? 2
  • +
  • -

#3 maria_six  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 24
  • Joined: 28-September 11

Re: Link click tracking without database

Posted 01 October 2011 - 12:27 PM

why after I click the link and the content disappears from the site

<?php
if(!file_exists('count.txt')){
  file_put_contents('count.txt', '0');
}
if($_GET['click'] == 'yes'){
  file_put_contents('count.txt', ((int) file_get_contents('count.txt')) + 1);
  header('Location: ' . $_SERVER['SCRIPT_NAME']);
  die;
}
?>


<?php echo file_get_contents('count.txt'); ?>
<a href="?download=file&click=yes"">download</a>



?download=file -> it contains
?download=file&click=yes -> no content

This post has been edited by maria_six: 01 October 2011 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 943
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Link click tracking without database

Posted 01 October 2011 - 03:58 PM

This approach only works for a single file. What do you mean by the content disappears?
Was This Post Helpful? 0
  • +
  • -

#5 maria_six  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 24
  • Joined: 28-September 11

Re: Link click tracking without database

Posted 02 October 2011 - 02:20 AM

part of the code of the site is there, the rest after that code disappears
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3394
  • View blog
  • Posts: 9,592
  • Joined: 08-June 10

Re: Link click tracking without database

Posted 02 October 2011 - 05:58 AM

Id hazard a guess that there is a PHP error. do you have error reporting & display enabled?
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Link click tracking without database

Posted 02 October 2011 - 06:37 AM

View Postmaria_six, on 01 October 2011 - 08:56 AM, said:

i would to help with link click counter without database

This is like saying you'd like to write a novel without using words.
You need to store the information somewhere, and that will end up being a database. Rolling your own database is going to be harder than using an existing one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1