Tell a friend
Link to us
Bookmark Us
Total Members
      Members: 87081
Sitemap Forum Chat
 
PHP Home
PHP Members (3665)
PHP Member Articles ( 10 )
PHP Discussion (15)
PHP Q & A ( 13 )
- PHP Ask Question
- PHP Questions
- PHP Unanswered Questions
PHP Resources
PHP Source Code (463)
PHP Articles (119)
PHP Blogs (37)
PHP Jobs (0)
PHP Components (25)
PHP Books (3)
PHP Websites (29)
PHP News (17)

 
Resource Directory
Code Snips & Functions (0)
Libraries & Component (2)
PHP Community (0)
PHP Web Hosting (0)
Software & Server (0)
Tutorials & Reference (0)
Web Applications (0)

 
GROUP INFO
Members: 3665
Access Type: Anyone can join

 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Javascript Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial
Tomcat Tutorial

RESOURCES
Q & A (531 )
Source Code (3276 )
Articles (365 )
Books (373 )
Components (1647 )
News (898 )
Websites (1208 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Authors
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Feedback
Tell a Friend
Advertise

 

Home > PHP > Member Articles > Architecture / Design >
 

Manually Expiring Web Pages


  Author : jlcfly
  Date Published : 06/25/2003
  Rating No Rating
  Accessed : 11728
   jlcfly

After going through a series of pages during a registration process, you don't want the user to be able to go back after the final submit. What can you do to manually "expire" those pages, and perhaps display a custom message?



In this scenario, I didn't want my session to expire as I needed it to continue. Instead, I used an extra session variable to track whether my session was alive or not. There are three main components: (1) the entry script, (2) the Cache-control directive, (3) the conditional check, and (4) manually expiring a portion of the session.



THE ENTRY SCRIPT



I use an entry script to start my session. This accomplishes two things:
(1) destroys any session already in progress, and (2) starts a new session.



entry.php:


session_start();
session_unset();
session_destroy();
session_start();
session_register('alive');
$_SESSION["alive"] = "1";
Header("Location:/php/createaccount.php");


In the above script, we start the session, get rid of any registered session variables with session_unset(), and destroy that session with session_destroy(). Then, we start a new session and register a session variable. This particular variable will track whether this portion of the session is alive or not. We set the variable to some value, then we redirect to our first page in the registration series.



CACHE-CONTROL AND CONDITIONAL CHECK



In the following code snippet, we will auto-detect if the session is still in use.



createaccount.php:


session_start();
header("Cache-control: must-revalidate");

if ($_SESSION["alive"] != "1") {
// User is attempting to go back after the session was destroyed
Header("Location:/php/error100.php");
}


The "Cache-control" directive above is very important. Using "must-revalidate" tells the browser that it has to fetch the page from the server again instead of loading if from its cache. Because it reloads the page from the server, it will re-check the $_SESSION["alive"] variable to see if its value is "1". If so, the page can load properly. If not, then we'll redirect the user to another page that contains a custom error message. Placing this script at the beginning of every page in the registration series will catch every "Back" button press by the user. It's not enough to place it on the last page in the registration series as a user could press the "Back" button more than one time. I have this snippet in createaccount.php, createaccount1.php, createaccount2.php and createaccount3.php.



MANUALLY EXPIRE THE SESSION



The last thing to do is manually "expire" the session, or at least a portion of it. In my case, I wanted the session to stay alive, so I could not use session_unset() or session_destroy(). However, I didn't want the user to go back to the previous pages and change things. Remember that $_SESSION["alive"] variable? After the final submit, all we have to do is get rid of it. There are two ways to do this:



createaccount4.php (the page after the final submit):


session_start();
$_SESSION["alive"] = "0";


or




session_start();
session_unregister('alive');


Either way will accomplish the same thing. Now, when the "Back" button is pressed, the user won't return the the previous page and be able to change data and resubmit. Instead, they will be redirected to error100.php (or whatever page you choose) and will get a custom error message.



So, the next time you want to stop the user from going back to change data previously entered, and if you want manual control over it, use this method. Just remember that the entry script sets the session variable to the "alive" state, and the exit script (right after your final submit during the process) sets the session variable to a "not alive" state. The "Cache-control: must-revalidate" forces the browser to reload the page from the server, and the "alive" check is performed. Redirection to a custom page occurs when the session variable is not "alive".





 
   Add Comment  Printer Friendly
   View All Comments  Email to a friend
   Add to my Favourites  Report Bad Submissions  Submit Feedback
   Rating Download PDF version
 
                 Click each image to add
this page to each site.
 
Related Articles of PHP
Previous Article    -     Random Articles    -     Next Article
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
 
 
 
 
Welcome Guest Signup
Member's Panel
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!

SEARCH
 



 
 
 
 
 


Home | Login | About Us | Contact Us | Privacy Policy | Advertising | Feedback Please