PHP Classes

File: aux_SafeCookie.php

Recommend this page to a friend!
  Classes of Ray Paseur   PHP Secure Cookie   aux_SafeCookie.php   Download  
File: aux_SafeCookie.php
Role: Auxiliary script
Content type: text/plain
Description: Auxilliary
Class: PHP Secure Cookie
Store cookies allowing to detect unwanted changes
Author: By
Last change:
Date: 5 years ago
Size: 707 bytes
 

Contents

Class file image Download
<?php // classes/aux_SafeCookie.php
/**
 * Damage a cookie
 */
error_reporting(E_ALL);

$cookie_name
= !empty($_GET['n'])
?
$_GET['n']
:
NULL
;

$cookie_value
= !empty($_GET['v'])
?
$_GET['v']
:
NULL
;

$host = $_SERVER['HTTP_HOST'];
if (
substr_count($host, '.') > 1) {
   
$host = explode('.', $host);
    unset(
$host[0]);
   
$host = implode('.', $host);
}


setcookie
( $cookie_name
, $cookie_value
, time() + 3600 // One hour into the future
, '/' // All sub-directories
, $host // Host name
, FALSE // OK to set on HTTP (not just HTTPS)
, TRUE // Restricted from Javascript
)
;

echo
PHP_EOL . "Cookie '$cookie_name' has been set to '$cookie_value'";