Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Grab";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

the question is not the topic Find similar branches


-=CrazyFish=-   (2001-11-09 16:28) [0]

People, I want to put file download counters on my page. Could you throw some kind of dock how to do it?
Thanks in advance.



Oleg Gashev   (2001-11-09 16:46) [1]

In Spylog is.



anod   (2001-11-09 17:16) [2]

The simplest on pearl

#! d: / web / perl / bin / perl -w

use strict;
use CGI;

my $ q = CGI-> new;
my% counter;

print $ q-> header (-charset => "cp-1251");
dbmopen (% counter, "counter", 0666);
$ counter {"Total"} = 0 if! $ counter {"Total"};
print ++ $ counter {"Total"};
dbmclose (% counter);

And they call him like this:
Visits: <! - # include virtual = "/ cgi-bin / counter.pl" ->



Donal   (2001-11-09 17:50) [3]

so in fact we are talking about download counters, not page impressions
and this is really done either in pearl, or in PHP, or in any other server script language ...
the bottom line is that instead of a link to a file, a link to a script is given with a parameter that uniquely identifies the file .. and the script increments the counter and gives the client the file itself ...
I’ll try to write in PHP, because it’s most interesting :-)). if that works out, let me know :-)



Donal   (2001-11-09 18:35) [4]

here is the result :-) so - the download counter (only accounting) in PHP:

anywhere in the site we write a catalog file where the names of files that can be downloaded are indicated and the number of downloads through the separator. The separator can be anything, the main thing is that it cannot be used in the file paths.
an example of such a file (here the separator is a space):
cat1 / subcat1 / file1.zip 0
cat2 / subcat2 / file2.zip 0

<? $ delimeter = ""; // set the delimiter $ catname = "filecat.txt"; // set the name of the directory file $ files = File ($ catname); // load the file list $ filelist = explode ($ delimeter, $ files [$ fileno], 2); // read the parameters $ filelist [1] + = 1; // increment the counter $ files [$ fileno] = implode ($ filelist, $ delimeter); // combine the parameters $ file = fopen ($ catname, "wt"); // open the file for overwriting for ($ i = 0; $ i <count ($ files); $ i ++) fputs ($ file, trim ($ files [$ i]). "\ n"); // write file data there fclose ($ file); // close the file header ("Location: {$ filelist [0]}"); // redirect the browser to the file ?>

how to use it:
on the page we put such a link HREF = "download.php? fileno = x"
where instead of x the file number in the list is substituted (starting from zero)
---
this example is a little flawed ... so, for good, you still need to lock the file so that there are no conflicts while accessing it.



anod   (2001-11-09 20:35) [5]

Oops, did not read ....



Anatoly Podgoretsky   (2001-11-09 22:48) [6]

If you want something good, then this is not enough, the following are possible improvements
1. instead of one file, one for each, favorably affects the speed and number of errors during locks, otherwise it is possible to block access to all files.
2. When blocking, it is necessary to additionally catch dead locks and delete them.

Without these precautions, problems are guaranteed, especially during intensive work.



Pages: 1 whole branch

Forum: "Grab";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top





Memory: 0.56 MB
Time: 0.036 c
1-22248
Leviathan
2001-12-17 13:07
2002.01.08
Delphi mocks !!!


1-22194
Type
2001-12-15 09:28
2002.01.08
Millet question!


3-21957
KMM
2001-11-29 15:31
2002.01.08
In the course of the program, it is necessary to create and delete a table many times ...


14-22362
MIFI
2001-11-04 02:34
2002.01.08
how to find a person


14-22381
Felix
2001-11-08 20:41
2002.01.08
What was that?





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish