Whiteknight
01-29-2004, 07:49 PM
I'm working on a javascript textcounter, for times when SSI isnt available for using a CGI script. here is my code so far, I have been working on it for a while, and can't seem to work the bugs out.
also, I'm not even sure if the I/O functions I am using even exist. I found a reference about them, but maybe that is my problem....
function counter()
{
//Path to data file.
var path_to_data = "/var/www/html/data/sitedata.txt";
var count; //the count variable
var count_file; //the file pointer to the data file
var file_status; //boolean file status indicator
//sets the pointer "count_file" to the indicated path
count_file = new File(path_to_data);
//determines that no previous lock is in place, and if not,
//opens the file for reading, or creates a new, blank file.
if( project.lock() );
{
//if the file does not exist, the file is created
file_status = count_file.open("r");
if(file_status = 0)
{
count = 0;
}
else
{
//if the file does exist, read the number, and save it to count
count_file.setPosition(0);
count = count_file.readln;
count_file.close();
}
//file is unlocked for more use
project.unlock();
}
//count is incremented
count += 1;
//project file is locked again
if( project.lock() )
{
//file is erased, and new count value is entered
count_file.open("w");
count_file.writeln(count);
count_file.close();
}
//file is unlocked
project.unlock();
//count value is returned to page.
return count;
}
Ideally, once I get this simple version working, I will begin work on a more versatile script that can count for multiple pages (either by having multiple data files, or by having a single datafile that is searched or something. but i can worry about that later.
anybody see my problem?
also, I'm not even sure if the I/O functions I am using even exist. I found a reference about them, but maybe that is my problem....
function counter()
{
//Path to data file.
var path_to_data = "/var/www/html/data/sitedata.txt";
var count; //the count variable
var count_file; //the file pointer to the data file
var file_status; //boolean file status indicator
//sets the pointer "count_file" to the indicated path
count_file = new File(path_to_data);
//determines that no previous lock is in place, and if not,
//opens the file for reading, or creates a new, blank file.
if( project.lock() );
{
//if the file does not exist, the file is created
file_status = count_file.open("r");
if(file_status = 0)
{
count = 0;
}
else
{
//if the file does exist, read the number, and save it to count
count_file.setPosition(0);
count = count_file.readln;
count_file.close();
}
//file is unlocked for more use
project.unlock();
}
//count is incremented
count += 1;
//project file is locked again
if( project.lock() )
{
//file is erased, and new count value is entered
count_file.open("w");
count_file.writeln(count);
count_file.close();
}
//file is unlocked
project.unlock();
//count value is returned to page.
return count;
}
Ideally, once I get this simple version working, I will begin work on a more versatile script that can count for multiple pages (either by having multiple data files, or by having a single datafile that is searched or something. but i can worry about that later.
anybody see my problem?