Manipulate the browser history in your web app.
I created this library to be able to easily come back to the browsed page after editing a resource. The possibility are endless with this package, which is easy to integrate as it is loosely coupled.
Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.
- folded/action: A way to organize your controllers for your web app.
- folded/config: Configuration utilities for your PHP web app.
- folded/crypt: Encrypt and decrypt strings for your web app.
- folded/exception: Various kind of exception to throw for your web app.
- folded/http: HTTP utilities for your web app.
- folded/orm: An ORM for you web app.
- folded/routing: Routing functions for your PHP web app.
- folded/request: Request utilities, including a request validator, for your PHP web app.
- folded/session: Session functions for your web app.
- folded/view: View utilities for your PHP web app.
- Stores the GET requests, by making sure there is not duplicate if the user browse again the same URL
- Can check if an history index exist
- Can get an URL by its history index, or get all the urls in the history
- Uses the PHP session to store the history
- PHP version >= 7.4.0
- Composer installed
In your root folder, run this command:
composer required folded/history
As early as possible, and by making sure the code is ran before your "controller" or "action" code, add this:
use function Folded\addRequestedUrlToHistory;
session_start();
addRequestedUrlToHistory();
Every time your user browse an URL, it will get added if it matches a GET request.
- 1. Get an history by its index
- 2. Get the last history
- 3. Get all the URLs in the history
- 4. Check if an index in the history is present
In this example, we will get the second last URL by its index in the history.
use function Folded\getHistory;
echo getHistory(-1);
This history starts from 0, and to get the earlier URL, you need to use negative indexes.
- An history of 0 will get the last URL
- An history of 1 will get the second last URL
- An history of 2 will get the URL before the second last
- ...
In this example, we will not use any argument to get the last URL in the history.
use function Folded\getHistory;
echo getHistory();
In this example, we will get all the history as an array.
use function Folded\getAllHistory;
$urls = getAllHistory();
foreach ($urls as $url) {
echo $url;
}
In this example, we will check if an url in the history at a specific index exists.
use function Folded\hasHistory;
if (hasHistory(-1)) {
echo "has history -1";
} else {
echo "has not history -1";
}
7.3 | 7.4 | 8.0 | |
---|---|---|---|
v0.1.0 | ❌ | ✔️ | ❓ |
v0.1.1 | ❌ | ✔️ | ❓ |
v0.1.2 | ❌ | ✔️ | ❓ |
v0.1.3 | ❌ | ✔️ | ❓ |