PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith  >  PHP Secret URL Path  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage Example
Class: PHP Secret URL Path
Authorize access based on user click sequence
Author: By
Last change: Added text to clarify default path sequence
Date: 3 years ago
Size: 1,210 bytes
 

 

Contents

Class file image Download
<?php
/*
secretPath class
version 1.0 10/21/2016

Authorize access based on the sequence of user clicks
*/

//start session - sequence saved in $_SESSION super global
session_start();

//include class source
include('secretpath.class.php');

//instantiate the class or define class object from saved data
if( empty($_SESSION['secpth']) ){
   
$path = array(1,2,3,2,2);
   
$secpth = new secretPath('link',$path);
}else{
   
$secpth = unserialize($_SESSION['secpth']);
}

//test user click sequence and send to secret page if sequence completed
//correctly
if( $secpth->validatePath() === true ){
   
   
//it is important to save the class object before re-directing
   
$_SESSION['secpth'] = serialize($secpth);
   
header('location: secret.php');
    exit;
   
}

//save class object to session
$_SESSION['secpth'] = serialize($secpth);

?>
<html>
    <head>
        <title>Secret Path Example</title>
    </head>
    <body>
        Default secret path is link: 1,2,3,2,2<br><br>
        <a href="example.php?link=1">Link 1</a><br>
        <a href="example.php?link=2">Link 2</a><br>
        <a href="example.php?link=3">Link 3</a><br>
    </body>
</html>