Jump to content

Execute code when user refreshes or clicks back.


matty

Recommended Posts

Hi,

 

Im looking for a way that i can run a function when a user refreshes a page, or clicks back.

This is so if a user does either of the above half way through completing a series of events, it will tell them for example they have to start again.

 

The only way i can think of doing this is to insert a value into a table (database) when they start the series of events and then remove it when they have completed, therefore if they goback/refresh or go to another page half way through that value will still be in the database and therefore the function will run. I will have something like

 

if($settings[site] == 'Y'){

        page("site");

exit;

}

 

At the top of each page.

 

Is there any alternatives?

 

Thanks, Matt

sounds like you want to use sessions.

 

<?php
session_start();

$this_page = 3; //presuming there were 2 pages before this one.

if($_SESSION['last_visited_page'] < $this_page){

  $_SESSION['last_visited_page'] = $this_page;

}elseif($_SESSION['last_visited_page'] == $this_page){

exit("you've already been to this page");
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.