• You are not logged in. | Login

Post a reply

  • Index
  •  » Help me!
  •  » File downloading counter that works from another site

January 19, 2007 9:26 am

n00bphp
Member
Ranks

File downloading counter that works from another site

Hallo, everybody! I need a counter of files’ download working from other site i.e. PHP-script is on another site and it is connected with the current one by means of javascript. ID for clicks counting is also added to files.
Has anyone seen something like that?


 

 

January 19, 2007 9:31 am

mastaweb99
Member
Ranks

Re: File downloading counter that works from another site

What for do you need such sophistications?  For example, it can be done like this:
CODE

<script>

var req;

filename="123.rar"; // name of a file 
url = "mysite.ru/counter.php?file="+encodeURIComponent(filename); // url, where "mysite.ru/counter.php" – is the address of a counter script 

function get_count(url) {
   // for all the browsers except for Internet Explorer
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = processReqChange;
       req.open("GET", url, true);
       req.send(null);
   // for Internet Explorer
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
           req.onreadystatechange = processReqChange;
           req.open("GET", url, true);
           req.send();
       }
   }
}

function processReqChange() 
{
   if (req.readyState == 4) {
       // only if "OK"
       if (req.status == 200) {
           count = req.responseText;  // In this variable the number of downloads returned by server will be saved.       }
   }
}

</script>

I think, script will get from the file’s name in GET-parameters, increase the downloads number at one and put it out.  I hope it’s clear how to do this.


 

 

January 19, 2007 9:38 am

phppat
Member
Ranks

Re: File downloading counter that works from another site

Such a sophistication…
PHP Code

// script on the remote host 
$id = $_GET['id'];
DB_connect();
$result = DB_query("UPDATE files SET downloads=downloads+1 WHERE id=$id");
header("Location: http: //some.other.site/download.php?id=$id");
exit;

PHP Code

// script on our host 
$id = $_GET['id'];
if($_SERVER['HTTP_REFERRER'] != "some.remote.host" || empty($_GET['id'])){
   list_files();
}
else{
   download_file($id);
}

And conversely…We add links like http://some.remote.host/count.php?id=$id and don’t need anything else.
If you wish you may rewrite the script for our host in javascript but you’d better do it in PHP (it’s securer).


PHP monster

 

 

January 19, 2007 9:43 am

n00bphp
Member
Ranks

Re: File downloading counter that works from another site

phppat, your script on the remote host is too short. And what about statistics? And what if we have 1000n files? What about distribution upon categories (units, pages)?
And about your ‘script on our site’: I need a connection on JS only…


 

 

January 19, 2007 9:46 am

phppat
Member
Ranks

Re: File downloading counter that works from another site

It doesn’t matter it is short. It is for recording only. You may add downloading time, country and anything you want according to your needs.
And JS-connection is simple:
CODE

<script language="javascript">
id = parseInt(location.search.substr(location.search.strpos("?id="), location.search.length));
if(document.referrer != "some.remote.host" || is_numeric(id) != true){
  list_files();
}
else{
  location.href = "some.remote.host/files/".files[id];
}
</script>

You need only to invent a method how to insert files into the list (as a variant you can form a correct massive in PHP-script on the remote server and connect it through

<script src="..."></script>)

Last edited by phppat (January 19, 2007 9:46 am)


PHP monster

 

 

January 19, 2007 10:00 am

n00bphp
Member
Ranks

Re: File downloading counter that works from another site

Is it possible to connect an already existing script?


 

 

January 19, 2007 10:01 am

senjor_itc
Member
Ranks

Re: File downloading counter that works from another site

google.com - look here.


 

 

January 19, 2007 10:05 am

phppat
Member
Ranks

Re: File downloading counter that works from another site

Changing scripts of the others is not a proper way. And besides that all the scripts like those function identically – there are two parts:
1) writes as much info as possible in the base by file downloading (browser, IP)
2) puts out statistics properly


PHP monster

 

 
  • Index
  •  » Help me!
  •  » File downloading counter that works from another site
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services