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!
Sat 31/05/03 at 16:07
Regular
"Pouch Ape"
Posts: 14,499
I'd look it up myself, but you people are so much help :D

PS, I'll show you why this afternoon sometime!
Sat 31/05/03 at 16:14
Regular
Posts: 20
monkey_man wrote:
> I'd look it up myself, but you people are so much help :D
>
> PS, I'll show you why this afternoon sometime!

First, create a blank file. Name it counterlog.txt

Then create a new file. Copy/paste this into it.

$viewss = file("counterlog.txt");
$views = $viewss[0]; $views++;
$fp = fopen("counterlog.txt", "w");
fwrite($fp, $views);
fclose($fp);
print $views;
?>


Save it as counter.php. Then you use include to get the code on whichever page you want.

include ("counter.php");
?>



Upload the files and chomod counterlog.txt to 766, and you should have a brand new counter

If you ever want to change the number of visitors (You evil cheater :P), open counterlog.txt, and edit the number to what you want. Remember to chmod it again when you're finished.

I hope this is what you were after?
Sat 31/05/03 at 16:17
Regular
"Pouch Ape"
Posts: 14,499
Cheers - it's for my new and improved chat room! I deleted the code that did the increment bit and couldn't remember how to do it.
Sat 31/05/03 at 16:34
Regular
"Pouch Ape"
Posts: 14,499
Hmm, it;s not working. I know PHP pretty well and how to set up permissions and stuff, yet this is still eluding me.
Sat 31/05/03 at 16:35
Regular
"Eff, you see, kay?"
Posts: 14,156
$var++ will increment a variable.

$var = 2;
echo $var++; // prints 2

$var = 2;
echo ++$var; // prints 3

$var = 2;
echo $var--; // prints 2

$var = 2;
echo --$var; // prints 1
?>

Any questions?
Sat 31/05/03 at 16:37
Regular
"Pouch Ape"
Posts: 14,499
OK, I have a file called "users.data". This needs to be opened, incremented, closed and then it's displayed somewhere. what you've said here all makes sense, but it's just not working!!! My permissions are right and the code is good, but the outcome is bad :(
Sat 31/05/03 at 16:41
Regular
"Eff, you see, kay?"
Posts: 14,156

$filename = ""; // relative path to the hits file (must have 666 perm
issions)

$fp = @fopen($filename,"r");
$counterval = @fread($fp, filesize($filename));
@fclose($fp);
$counterval = (integer)$counterval + 1;
$fp = @fopen($filename,"w+");
@fwrite($fp, $counterval, 26);
@fclose($fp);

?>

Then you can just slap in wherever.
Sat 31/05/03 at 16:43
Regular
"Pouch Ape"
Posts: 14,499
What's with all the @'s?
Sat 31/05/03 at 16:44
Regular
"Eff, you see, kay?"
Posts: 14,156
@s are for people with skillz.

Or maybe for people without skillz... whatever. Anyway, they supress errors and warnings, which is bloody useful when you have a function that works as you want it to but displays a warning about something or other.
Sat 31/05/03 at 16:49
Regular
"Pouch Ape"
Posts: 14,499
Hmmm. I don;t get an error where I was before, but the users.data file hasn't changed from "0" and it's not including either.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Thank you very much for your help!
Top service for free - excellent - thank you very much for your help.
My website looks tremendous!
Fantastic site, easy to follow, simple guides... impressed with whole package. My website looks tremendous. You don't need to be a rocket scientist to set this up, Freeola helps you step-by-step.
Susan

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.