PHP Classes
elePHPant
Icontem

Really great idea and example! Be great if could submit numb...

Recommend this page to a friend!

      PHP Secret URL Path  >  All threads  >  Really great idea and example! Be...  >  (Un) Subscribe thread alerts  
Subject:Really great idea and example! Be...
Summary:Package rating comment
Messages:5
Author:Terry Woody
Date:2016-12-21 23:08:24
 

 

Terry Woody rated this package as follows:

Utility: Good
Consistency: Good
Documentation: Good
Examples: Good

  1. Really great idea and example! Be...   Reply   Report abuse  
Terry Woody - 2016-12-21 23:08:24
Really great idea and example!

Be great if could submit numbers (links) using ajax so page did not refresh each time though. Maybe using buttons 1-9 or something like https://jsfiddle.net/qekeztn2/

If I were sharp enough, would make the mod but out of my league:)

Nevertheless, thumbs up and thank you for sharing.

Cheers,

Woody


  2. Re: Really great idea and example! Be...   Reply   Report abuse  
Dave Smith - 2016-12-22 01:09:42 - In reply to message 1 from Terry Woody
The example is a simple implementation to demonstrate the basic usage, however the idea is to actually link to different pages on your site so that the user has to navigate these pages correctly to be validated.

The jsfiddle example you provided uses javascript, not ajax, and is not the right direction.

If you wanted to stay on the same page without the refresh, you would use ajax. I would use jquery, which has decent ajax implementation. Basically you would use the click() event handler to send an ajax request to a processing file which would return false or true if the secret path was completed successfully. If it returned true, you could then send the user to the hidden page.

Your process file would look something like this...

<?php
session_start();
include('secretpath.class.php');
if( empty($_SESSION['secpth']) ){
$path = array(1,2,3,2,2);
$secpth = new secretPath('link',$path);
}else{
$secpth = unserialize($_SESSION['secpth']);
}
echo $secpth->validatePath();
$_SESSION['secpth'] = serialize($secpth);
?>

Dave

  3. Re: Really great idea and example! Be...   Reply   Report abuse  
Terry Woody - 2016-12-22 15:29:03 - In reply to message 2 from Dave Smith
Thanks for input Dave.

Had tried the ajax route before posting here using a process.php:

<?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);

?>

and get the error:

Call to a member function validatePath() on null on line 25

(note: using your example get error on line 10)

Must be my actual ajax script. Wasn't positive if ajax would even work with your class, will explore little deeper.

Cheers!

  4. Re: Really great idea and example! Be...   Reply   Report abuse  
Dave Smith - 2016-12-25 06:18:29 - In reply to message 3 from Terry Woody
I finally got a chance to work up a proof of concept, here is what worked for me...

ajaxtest.html

<html>
<head>
<title>Secret Path Example</title>
<script src="jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function(){
$("#clickEvent a").click(function(e){
var idVal = $(this).attr('id');
e.preventDefault();
$.ajax({
method: "POST",
url: "process.php",
data: { link: idVal }
})
.done(function( returnVal ) {
if( returnVal == true ){
alert('True');
}else if( returnVal == false ){
alert('False');
}else{
alert('Error');
}
});
return false;
});
});
</script>
</head>
<body>
Default secret path is link: 1,2,3,2,2<br><br>
<div id="clickEvent">
<a href="?link=1" id="1">Link 1</a><br>
<a href="?link=2" id="2">Link 2</a><br>
<a href="?link=3" id="3">Link 3</a><br>
<a href="?link=4" id="4">Link 4</a><br>
<a href="#" id="0">Link 5</a><br>
</div>
</body>
</html>

process.php

<?php
session_start();
include('secretpath.class.php');
if( empty($_SESSION['secpth']) ){
$path = array(1,2,3,2,2);
$secpth = new secretPath('link',$path);
}else{
$secpth = unserialize($_SESSION['secpth']);
}
echo $secpth->validatePath();
$_SESSION['secpth'] = serialize($secpth);
?>

reset.php

<?php
session_start();
if( !empty($_SESSION['secpth']) ){
unset($_SESSION['secpth']);
}
echo 'reset complete';
?>

Nothing fancy here, each click will present a dialog that displays what was returned... true, false or error. Should return true when the path was successfully completed.

The reset.php file should be ran to reset the session after a successful completion of the path.

Dave

  5. Re: Really great idea and example! Be...   Reply   Report abuse  
Terry Woody - 2016-12-26 19:59:47 - In reply to message 4 from Dave Smith
That was very nice of you Dave.

Appreciate the example much!

Woody