Solved

Decrease a variable by one when the user leaves the page?

Posted on 2004-10-01
8
242 Views
Last Modified: 2008-02-26
Hi,

How can decrease a variable by one when the user leaves the page?
I.E:
$visfile=fopen("visitors1.txt", "r");
$visitors=fread($visfile, filesize("visitors1.txt"));
$visitors=$visitors + 1;
$visfile2=fopen("visitors1.txt", "w");
fwrite($visfile2, $visitors);
fclose($visfile2);
echo "Current Session Users: " . $visitors;
fclose($visfile);
Adds 1 to the file when the user comes to the page, but how do i set $visitors relative to -1? Any help would be much apreciated.

Thx,
Jamison
0
Comment
Question by:Gonavitch
  • 2
8 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 67 total points
Comment Utility
Hey, not sure what you're really talking about...

You can do this:

$visfile=fopen("visitors1.txt","r+");
$visitors=fread($visfile,filesize($visfile));
$visitors+=1;
reset($visfile);
fwrite($visfile,$visitors);
fclose($visfile);

echo "Current Session Users: " . $visitors;



If you want it relative to -1, start off by putting -1 inside visitors1.txt
0
 
LVL 4

Assisted Solution

by:cachedVB
cachedVB earned 67 total points
Comment Utility
make it an onunload event in javascript
0
 
LVL 1

Author Comment

by:Gonavitch
Comment Utility
never mind, i solved my problem.
0
 
LVL 4

Expert Comment

by:cachedVB
Comment Utility
Doesn't he need to post his answer? I am curious on ohow he did it.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now