grayscale2005. Posted May 18, 2007 Share Posted May 18, 2007 hi can anyone show me the code i need to check if page has been refreshed and if it has i don`t want the code below to be executed. $sql = "UPDATE " . USERS_TABLE . " SET user_travel = user_travel + 1 WHERE user_id = '" . $userdata['user_id'] . "'"; if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_ERROR, 'Could not update travel', '', __LINE__, __FILE__, $sql); } thankyou. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/ Share on other sites More sharing options...
per1os Posted May 18, 2007 Share Posted May 18, 2007 The only "way" is to use session. But even then it does not necessarily mean the page was refreshed. As far as almost anyone is concerned if you figure out this one, you will of made a ground breaking discovery. I am still trying to figure this out. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/#findComment-256670 Share on other sites More sharing options...
grayscale2005. Posted May 18, 2007 Author Share Posted May 18, 2007 oh thanx. i think i have to try stop the page refresh then. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/#findComment-256677 Share on other sites More sharing options...
per1os Posted May 18, 2007 Share Posted May 18, 2007 Not gonna happen. If you are worried about the POST data etc, what I would suggest is re-directing to a page after the SQL statement using header to clear the post/get data so when a refersh is done it doesn't insert twice. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/#findComment-256681 Share on other sites More sharing options...
pocobueno1388 Posted May 18, 2007 Share Posted May 18, 2007 As Frost just said, it isn't possible to tell when the page is refreshed. There are some methods you can use like registering a session when they visit that page, then if the session is registered don't allow them to get back on the page...but the session will expire and they will be able to visit the page again. If this is a user registering site, you could always put a field in the user table of the DB called something like "last_visit" and make it a timestamp. Then update it when they visit the page, and don't let them back on the page until they haven't been to it in X amount of time. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/#findComment-256683 Share on other sites More sharing options...
siwelis Posted May 18, 2007 Share Posted May 18, 2007 When using a FORM have a unique ID of the form posted into a temporary table with the users IP address and unless the FORM page (not POST page) is refreshed, a new unique ID will not be developed (or you could make it so the unique ID sticks if you don't want them viewing that page ever again, and then not make it a temprary table) On page open the top script checks if the page has been used, checking to see if the IP address of the user has the same unique ID as last used, then page diverts. I hope that made sense there! My logic is good, my communication is rushed lately, and my PHP language is still developing. The basics of the code if written should work though. Store in temp table if user has been there before by using a unique id generated on post if unique id has been used before for that POST page, then process no more script. Just make sure the unique id is generated ONLY if none exists for that USER on that particular page. Quote Link to comment https://forums.phpfreaks.com/topic/52064-help-code-to-check-if-page-was-refreshed/#findComment-256699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.