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.
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
"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
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
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
"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
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!
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
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: