PHP code example of marcocesarato / security

1. Go to this page and download the library: Download marcocesarato/security library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marcocesarato / security example snippets


use marcocesarato\security\Security;



$conn = new PDO(...);
Security::setDatabase($conn); // Or Security::$database = $conn;

$isAPI = false; // default is FALSE (this remove some check that could block API request)
$security = new Security($isAPI);

$isAPI = false; // default is FALSE
Security::putInSafety($isAPI);

$GLOBALS['UNSAFE_SERVER'] = $_SERVER;
$GLOBALS['UNSAFE_COOKIE'] = $_COOKIE;
$GLOBALS['UNSAFE_GET'] = $_GET;
$GLOBALS['UNSAFE_POST'] = $_POST;
$GLOBALS['UNSAFE_REQUEST'] = $_REQUEST;

$is_html = true;        // default is TRUE
$have_quotes = true;    // default is TRUE
$escape_string = true;  // default is TRUE except if you set FALSE in class config
$var = Security::clean($_POST['var'], $is_html, $have_quotes, $escape_string);
echo $var; 

Security::cleanGlobals();

ob_start()
    
// ... Your code ...
    
echo Security::output(ob_get_clean());

Security::$session_name = "MYSESSID";

// Error Template
$error_callback = null; // Set a callback on errors
$error_template = '<html><head><title>${ERROR_TITLE}</title></head><body>${ERROR_BODY}</body></html>';