Jump to content

[help] code to check if page was refreshed


grayscale2005.

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.