GetDotted Domains

Viewing Thread:
"PHP for incrementing a variable please."

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Sat 31/05/03 at 16:07
Regular
Posts: 787
I'd look it up myself, but you people are so much help :D

PS, I'll show you why this afternoon sometime!
Sun 01/06/03 at 11:44
Regular
"Pouch Ape"
Posts: 14,499
I find that I've always been able to create, read and write to ".data" files that have been created "on the fly" with FREEOLA. There was a problem once when they moved the servers and the permissions were defaulted, but that was sorted and it's all fine now. what I was using this code for wasn't strictly a hit counter - it only incremented if the sign-in was successful, providing a data file that tells me how many users are signed up.
Sat 31/05/03 at 21:41
Regular
"Eff, you see, kay?"
Posts: 14,156
Yeah creating new files on the filesystem is really, really dodgy with PHP, and indeed most languages.
Sat 31/05/03 at 21:05
Regular
"Chavez, just hush.."
Posts: 11,080
doc693 wrote:
> 'w' - Open for writing only; place the file pointer at the beginning
> of the file and truncate the file to zero length. If the file does not
> exist, attempt to create it.

Freeola doesn't seem to allow files to be created like this.

I used a small user online script, on Lycos it created the text log file but on Freeola it just produced an error. I had to create the text file by uploading a blank file and renaming it.
Sat 31/05/03 at 20:53
Regular
"whoneedsatagline?"
Posts: 194
From the PHP manual ...

'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

Also, you do need to be careful with counters, if your site is at all busy, in case two clients are using the file at the same time - its all too easy for one to be updating the file just as the second is reading it, and then you get odd results to say the least, or the counter can revert to zero. I had code almost the same as yours, and kept finding that the file had been reset or corrupted.

Eventually I found that the best way is to have two files - the counter file itself, and another "lock" file. The process is:

Open the "lock" file and attempt to lock it
If you succeed, only then open the counter file, increment and update it
Then close both files

Sure, it means that if a second client arrives at the same time as someone is updating the counter, then they skip the update and you miss a count, but I got tired of having to deal with corrupted files before I used this locking.
Sat 31/05/03 at 17:05
Regular
"Eff, you see, kay?"
Posts: 14,156
Sexy.
Sat 31/05/03 at 17:03
Regular
"Pouch Ape"
Posts: 14,499
Cool. Well, I'm off now - it works, but you can't post there yet - http://www.pocketmonkey.co.uk/forums.php

I think it's nice.

Cheers Turbo!
Sat 31/05/03 at 17:01
Regular
"Eff, you see, kay?"
Posts: 14,156
I don't think it matters which you use.

I think (and this is a stab in the dark) if you 666 the folder, all subsequent files created in there will have 666 properties.
Sat 31/05/03 at 16:59
Regular
"Pouch Ape"
Posts: 14,499
It still works without the + bit - is that good or bad?
Sat 31/05/03 at 16:58
Regular
"Pouch Ape"
Posts: 14,499
D'oh! I thought it was just the folder you had to do that to!!! It works now, but will I have to do that for every .data file I make? I swear I never had to before because my last chat room relied on this same system. Anyway, it'll do for today - it's too hot and I need a shower.

Cheers TN!
Sat 31/05/03 at 16:56
Regular
"Eff, you see, kay?"
Posts: 14,156
monkey_man wrote:
> Looks like the last three lines of the code - is that "w+"
> meant to be there?

The code is fine, it's lifted from my website.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Great services and friendly support
I have been a subscriber to your service for more than 9 yrs. I have got at least 12 other people to sign up to Freeola. This is due to the great services offered and the responsive friendly support.
Second to none...
So far the services you provide are second to none. Keep up the good work.
Andy

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.