Solved

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

Posted on 2004-10-01
8
281 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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