Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session help

Status
Not open for further replies.

iostream71

Programmer
Mar 13, 2002
229
US
i was using this script to test a no reloading hit counter:

<?php
session_start();
$filename = &quot;counter.dat&quot;;
$fp = fopen ($filename, &quot;r&quot;);
$hits = fread ($fp, filesize($filename));
fclose ($fp);
//add hit if no session active
if (!isset($HTTP_SESSION_VARS['count'])) {
//was using: session_register('count'); but never
//would enter 'if'
$HTTP_SESSION_VARS['count'] = 1;
$hits++;
$fp = fopen( $filename,&quot;w&quot;);
fwrite($fp, $hits, filesize($filename));
fclose( $fp );
}
//write to flash
print &quot;&counterValue=&quot;;
print $hits;
?>

problem is, it resets to 1 after 10 hits every time.
here is my phpinfo:
 
Something is wrong with the file operation.

function fread(),fwrite() read or write binary datas into
a file.But your $hits is a string,that's to say,10 means
character 1 and 0,2 bytes.Therefore when you want to write 10 to file,in fact you write 1 to file because filesize() returns 1 byte.

If you want to solve this problem,you can define the file size by yourself or replace the filesize() with strlen($hits).

enjoy yourself.
 
but i do the exact same thing with another script and it works(the reading writing part). i have a value that's passed into the script from flash and it writes it no problem. is that a different situation?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top