Solved

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

Posted on 2004-10-01
8
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
8 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 67 total points
ID: 12203008
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
ID: 12203526
make it an onunload event in javascript
0
 
LVL 1

Author Comment

by:Gonavitch
ID: 12204947
never mind, i solved my problem.
0
 
LVL 4

Expert Comment

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

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

729 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