Solved

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

Posted on 2004-10-01
8
272 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

808 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