Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seikan/Page
A collection of useful page functions for PHP web application.
https://github.com/seikan/Page
Last synced: 5 days ago
JSON representation
A collection of useful page functions for PHP web application.
- Host: GitHub
- URL: https://github.com/seikan/Page
- Owner: seikan
- License: mit
- Created: 2017-10-07T10:30:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T00:54:44.000Z (over 6 years ago)
- Last Synced: 2024-08-01T19:53:14.007Z (3 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - seikan/Page - A collection of useful page functions for PHP web application. (PHP)
README
# Page
This is a collection of useful page functions for PHP web application.
## Usage
### Getting Started
> \$page = new Page( );
```php
// Include core Page library
require_once 'class.Page.php';// Initialize Page object
$page = new Page();
```### Client IP Address
Gets client IP address.
> **string** \$page->getClientIp( );
```php
// Display visitor IP address
echo 'You are connected from'.$page->getClientIp().'.';
```### Current URL
Gets current page URL.
> **string** \$page->getCurrentUrl( );
```php
// Display current page URL
echo $page->getCurrentUrl();
```### User Agent
Gets browser user agent.
> **string** \$page->getUserAgent( );
```php
// Display user agent
echo 'User Agent: ' . $page->getUserAgent();
```### Page Referer
Gets page referrer.
> **string** \$page->getReferer( );
```php
// Display page referer
echo $page->getReferer();
```### HTTPS
Checks if current page is HTTPS.
> **bool** \$page->isHttps( );
```php
// Redirect to HTTPS if current page is not HTTPS
if (false == $page->isHttps()) {
header('Location: https://www.example.com');
die;
}
```### Rewrite URL
Rewrites URL with new query string.
> **string** \$page->rewrite( **string** \$url\[, **array** \$queries\] );
```php
$url = 'http://www.example.com/home.php?page=2&action=show&sort=date';// Rewrite URL with new query string
echo $page->rewrite($url, [
'page' => 3,
'sort' => 'name',
]);
```**Result:**
```
http://www.example.com/home.php?page=3&action=show&sort=name
```###IsPost
Check whether the page request is a POST request.
> **bool** \$page->isPost();
```php
if ($page->isPost()) {
echo 'A form is posted.';
}
```### Request
Gets a value in HTTP `GET` or `POST` request.
> **string** \$page->request( **string** \$key\[, **int** \$method = Page::BOTH\] );
**Method**
`Page::BOTH` Returns values in GET or POST that matches the key provided.
`Page::GET` Returns values in GET that matches the key.
`Page::POST` Returns values in POST that matches the key.
```php
// URL - http://www.example.com/home.php?page=1&sort=name&text=Exampleecho 'Sort: '.$page->request('sort').'
';
echo 'Text (HTML): '.$page->request('text').'
';
```**Result:**
> Sort: name
> Text (HTML): Example### Get Server Variables
Gets a single or an array of server variable.
> **string** \$page->getVariable( **string|array** \$key );
```php
// Get browser language
echo "Browser Language: " . $page->getVariable('HTTP_ACCEPT_LANGUAGE');// Get multiple server variables
$values = $page->getVariables(['SERVER_PROTOCOL', 'REQUEST_METHOD', 'QUERY_STRING']);echo "Protocol : " . $values['SERVER_PROTOCOL'] . "\n";
echo "Method : " . $values['REQUEST_METHOD'] . "\n";
echo "Query : " . $values['QUERY_STRING'] . "\n";
```### Set Cookie
Sets a cookie.
> \$page->setCookie( **string** \$name, **string** $value\[, **int** \$day\[, **string** \$path = '/'\[, **string** \$domain = ''\[, **bool** \$secure = false\[, **bool** \$httpOnly = false\]\]\]\]\]\]);
```php
// Set cookie
$page->setCookie('username', 'foo', 1);
```### Get Cookie
Gets a cookie by name.
> \$page->getCookie( **string** \$name);
```php
// Get cookie
echo $page->getCookie('username');
```**Result:**
> foo
### Delete Cookie
Deletes a cookie by name.
> \$page->deleteCookie( **string** \$name);
```php
// Delete cookie
$page->deleteCookie('username');
```