GithubHelp home page GithubHelp logo

tracking's Introduction

Tracking

This is a simple class to track the previously visited pages in the session and easily move between them. This is helpful in situations where you need to redirect the user back to for example the page before login page.

Usage example

<?php

use Tracking\Tracker;

spl_autoload_register();

session_start();

// Add this line to all requests you want to track.
Tracker::instance()->save();

// In the following examples I will leave all url generating to you, You shouldn't write them manually like
// the way I'm doing here.

// Let's assume that the user has visited the following pages in order
// home -> product -> about-us -> login
// Now assume in the login page he entered the correct username and password, and you
// need to redirect him to the last page he was visiting. That's easy...
$redirectUrl = Tracker::instance()->getBefore('http://www.example.com/login');

// Great this redirectUrl will contain the url to the about us page.

// But what if you don't want him to go to the about us? You can specify except urls array in the
// second parameter.
// This will get the product page url..
$redirectUrl = Tracker::instance()->getBefore('http://www.example.com/login', array('http://www.example.com/about-us'));


// You can also get the visited page by order like so
$url = Tracker::instance()->getByOrder( 4 ); // Home page
$url = Tracker::instance()->getByOrder( 1 ); // Login page


// You can also set another mechanism to save identifier to the current request.
// e.g. in Laravel framework you can use the current route name instead of full urls if you make sure 
// all routes in your application are given names.
Tracker::instance()->setMechanism(function()
{
	// This is in laravel framework but you can return any thing that identify this request
	return Route::currentRouteName();
});

// You can also reverse the save order you made earlier by calling this method
Tracker::instance()->dontSave();

// You can also clear all previously tracked pages
Tracker::instance()->clear();

// At the end of all requests call the done method
Tracker::instance()->done();

tracking's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.