IF statement to check whether page is a refresh or not

Hi all, I have been giving myself a headache for nearly two weeks. I have been hunting high and low for possible solutions but have not come across anything that has helped me work it out.

What I’m trying to do is:

  1. Check if the page has been accessed in the correct manner (sent from a page called ‘generated’).

  2. If it has, display information from the database and add to a counter.

  3. If the page is refreshed, display same information but don’t add to counter.

  4. If the page has been accessed directly, inform the user.

I seem to have developed some seriously convoluted code, but I shall display it anyway in a manner that I hope is understandable.

if ((isset($_SESSION['fromGeneratedPage']) && $_SESSION['fromGeneratedPage']) && (!isset($value) || $value > 0)) {
	echo row['name'];
	$seen = row['seen'];
	$seen = seen + 1;
	echo $seen;
	$updateSeen = "UPDATE record SET seen= $seen WHERE id = $required_id";
            $stmt = $conn->prepare($updateSeen);
	$value = 1;
	} elseif (!isset($_SESSION['fromgenerated'])) {
	     echo row['name'];
             echo row['seen'];
	} else {
		echo 'This page has been accessed directly!';

If any clarification is required, just let me know and I’ll try and explain myself better.

Can you be pls more specific?
For the third question I’ll suggest you to add a date column into database and when the time that you refresh the page <= 3600sec (1 hour at unix system eg time()<=time_column+3600) then the code $seen=$seen+0 and if the time of refresh page is > 3601 then $seen=$seen+1.
I hope to give you an idea.

Thanks for your reply. Which part did you want me to be more specific on?

I see where you’re coming from with using unix time. I never thought about using that and I can certainly see that working. It also means that I can ensure that the ‘seen’ variable isn’t increased too quickly.

I will give it a try tomorrow and see how it pans out. But yes, it does seem to solve the problem I’m having. Thanks :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.