oenkitt
02-27-2010, 06:32 PM
There are a few pages of my site that I want users to be able to view only once a week/biweekly/monthly/etc (basically, just once per "round"). So far I've done this by just setting up a table in my database to keep track of how many times each user has viewed each page, and I just reset it whenever I want them to be able to view it again. But recently some of my users have told me that, occasionally, when they visit one of these pages, it tells them that they've already been there before?
The only thing I can think of is that their browsers are randomly reloading the pages for some reason, because the script on those pages is still being executed, but the users never get chance to see the output. It's fairly important for them to be able to see the script's output before they get "locked" out of the page, so is there a way to get around this?
Here's the part of the code that handles logging and such:
$activityinfo = get_table_info( activities, $activityid ); // gets the page's info
$log = $activityinfo['log']; // get the field name for the page's log
$loginfo = get_table_info_name( log, $_SESSION['username'] ); // gets user's page log info
if ( $loginfo[$log] == 0 && isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true ) { log ( $_SESSION['username'], $log ); $temppage = on; include 'temppage.php'; } // if they haven't viewed the page this round and they're logged in, log that they have viewed the page AND include the page
else if ( $loginfo[$log] > 0 ) { echo '<h1>Error</h1> Sorry, you\'ve already visited this round.'; } // OR if they have already viewed the page, show an error
else if ( !isset($_SESSION['logged_in']) || $_SESSION['logged_in'] == '' ) { echo '<h1>Error</h1> You must be logged in to view this page! Please <a href="/login.php">log in</a> and try again.'; } // OR if they're not logged in, direct them to log in page
else { echo '<h1>Error</h1> There was an error processing the page.'; }
The only thing I can think of is that their browsers are randomly reloading the pages for some reason, because the script on those pages is still being executed, but the users never get chance to see the output. It's fairly important for them to be able to see the script's output before they get "locked" out of the page, so is there a way to get around this?
Here's the part of the code that handles logging and such:
$activityinfo = get_table_info( activities, $activityid ); // gets the page's info
$log = $activityinfo['log']; // get the field name for the page's log
$loginfo = get_table_info_name( log, $_SESSION['username'] ); // gets user's page log info
if ( $loginfo[$log] == 0 && isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true ) { log ( $_SESSION['username'], $log ); $temppage = on; include 'temppage.php'; } // if they haven't viewed the page this round and they're logged in, log that they have viewed the page AND include the page
else if ( $loginfo[$log] > 0 ) { echo '<h1>Error</h1> Sorry, you\'ve already visited this round.'; } // OR if they have already viewed the page, show an error
else if ( !isset($_SESSION['logged_in']) || $_SESSION['logged_in'] == '' ) { echo '<h1>Error</h1> You must be logged in to view this page! Please <a href="/login.php">log in</a> and try again.'; } // OR if they're not logged in, direct them to log in page
else { echo '<h1>Error</h1> There was an error processing the page.'; }