The Daily Click ::. Forums ::. General Chat ::. Download Counters?
 

Post Reply  Post Oekaki 
 

Posted By Message

eyeangle



Registered
  12/06/2003
Points
  1683
31st July, 2003 at 22:49:28 -

I need to know how to put download counters on my site so people can view the number of downloads for my games. If anyone knows how to do this please mail me or post it here.
Thanks.

 
theonecardgame.com

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 01:52:55 -

1. What language are you using?
2. Will it be a community site or a personal site? (makes a difference as to the easiest way to code it)

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
1st August, 2003 at 02:11:42 -

If http://www.geocities.com/eyeangle2002 is your site, geocities tells you how many downloads you have in it's file manager.

-Andy

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

eyeangle



Registered
  12/06/2003
Points
  1683
1st August, 2003 at 02:42:40 -

I'm using Java and it's my personal site for the community. Well I'm making it in front-page. Where abouts does it say in geocities?

 
theonecardgame.com

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 03:43:12 -

Well, JavaScript (I assume you mean) isnt very helpful as that is client-side; you need a language that is server-side so you can save the download count on your server.

If you could tell me which scripting languages (server-side) your host supports then I can help you.

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
1st August, 2003 at 05:09:12 -

Geocities only supports plain HTML, I think

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14562

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
1st August, 2003 at 07:21:06 -

you could just have a seperate page to download the game and include a counter on that page
its easy to find free counters from elswhere because i think geocities only allows one counter per website

 
.

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 08:30:16 -

I've sent him to SpacePorts (as that supports PHP)... so below is some code you could use...

To Add to the Counter when Downloading:

<?
  $DH = fopen("./dlcount.txt", "r");
  $DC = fread($DH, filesize("./dlcount.txt"));
  $DH = fopen("./dlcount.txt", "w");
  fwrite($DH, ++$DC);
  fclose($DH);

  header("Location: ./myfile.zip");
?>

To Load the Counter Value:

<?
  $DH = fopen("./dlcount.txt", "r");
  $DC = fread($DH, filesize("./dlcount.txt");

  echo($DC);
?>

When loading the counter value, just use server-side includes with a pre-existing HTML document:

>!-- #include file="myscript.php" --<

I havent included any error checking (this is the most basic script you'll ever get as far as download counters go).

BTW, DH stands for "Download Counter File Handle" and DC stands for "Download Count".

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 08:33:43 -

Something I forgot to mention is that depending on the server you may need to use "wb" and "rb" to access in Binary mode (Windows). I'm not sure what OS SpacePorts is running, but if it doesnt work, try using "wb" and "rb" instead of just "w" and "r".

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Blake



Registered
  13/07/2002
Points
  179
1st August, 2003 at 11:47:35 -

nice

Image Edited by the Author.

 
"He who laughs last thinks slowest"

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
1st August, 2003 at 11:51:13 -

(n\m )

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Matt Boothman

The Nissan Micra of forum members

Registered
  20/09/2002
Points
  108

Game of the Week Winner
1st August, 2003 at 14:42:30 -

I am trying to get to learn PHP but it's so hard, is there anywhere offering beginner tutorials and not just ones with complicated text (AKA http://perl.about.com/cs/beginningphp/a/040703a.htm?zIr=1).
That is meant to be a beginner tutorial!

 
http://soundcloud.com/normbo - Listen to my music.

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 17:00:55 -

Noodle: have you programmed before? Picking up your first language is quite hard for most people.

Look at my scripts above, they're quite basic in that they only have a couple of lines.

I'll explain the second script first (I'll assume you already know about variables and functions, if not, tell me and I'll explain fruther)...

The Second Script
The first line executes the fopen function which, you could probably guess, opens a file. The first parameter specifies the file name, and the second specifies the mode you want to open the file with. In this case "r" has been used to specify Read mode, but you can also use "w" for Write mode and "a" for Append mode (there are other modes, but not important at this stage). The difference between Write and Append is that Write will remove the contents of the file when you load it, where as Append will add to whatever information already exists within the file. The function returns a pointer (sometimes called a "handle") to the start of the file on the disk.

So the first line now gives you a variable (called $DH in my example) which points to a file on the disk opened in Read mode.

The second line uses the fread function to read the file into a variable so we can use it inside the script. The first parameter is the file handle that we created earlier so that the script knows where to read from, and the second parameter is another function called filesize. This function will return the length of the file (in bytes) so that the fread function knows how many bytes it should read (in this case, the entire file). The information from the file that has been read is stored in the $DC variable.

The third line has an echo function, which simply prints text back to the web browser. In this case, it's just printing the number.

The First Script
The first line, like in the last example, loads the file in Read mode and returns a pointer.

The second line, like in the last example, reads the value contained within the file.

The third line re-opens the original file, but this time in Write mode (as you can see, the second parameter is "w" instead of "r"). It works in the same way by returning a pointer.

The fourth line uses a bit of a trick. The first thing to execute on this line is the ++$DC. What this does is it adds 1 to the value of that variable (so whatever the download count was, it will be increased by 1). Another shorthand you can use is $DC++, however the difference between these two statements is that ++$DC will increment the value of the variable BEFORE the rest of the line is executed, and $DC++ will increment AFTER the line has been executed, meaning if you use $DC++ instead, then you'll simply be writing the old (un-incremented) value back to the file, so the download count will never be increased from 0.

The fwrite function writes to the pointer specified in the first parameter the value of the second parameter (the incremented variable).

The fifth line closes the file (important!) this will allow other scripts to access the file (as no two scripts can access the same file at once, if you leave the file open, you'll have to wait for it to time out on the server).

The final line redirects the browser to the ZIP file containing the game. The only part of this line that is PHP is the header function, the "Location: ./myfile.zip" is a HTML header (generic and can be used in any language) to redirect the browser to any location. Redirecting to a file will cause the "download" dialog to appear (unless the server has been misconfigured, in which case you'll get a bunch of jibberish )

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
1st August, 2003 at 17:03:29 -

I realised after saying that, that I forgot to close the file on the second script... and I forgot a bracket (you wouldnt think I'd make 2 mistakes in a 3 line script, would you? )... it should be:

<?
  $DH = fopen("./dlcount.txt", "r");
  $DC = fread($DH, filesize("./dlcount.txt"));
  fclose($DH);

  echo($DC);
?>

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Matt Boothman

The Nissan Micra of forum members

Registered
  20/09/2002
Points
  108

Game of the Week Winner
2nd August, 2003 at 09:09:12 -

That explains some bits, but I still don't know how to write one or what it does.

I've only ever done HTML and CSS, but never anything that looks anything like PHP.

 
http://soundcloud.com/normbo - Listen to my music.
   

Post Reply



 



Advertisement

Worth A Click