Skip to content

Instantly share code, notes, and snippets.

@mehdichaouch
mehdichaouch / memory_usage.php
Last active October 14, 2024 10:53
PHP Snippet to get human readable memory usage
<?php
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
convert(memory_get_usage());
@irazasyed
irazasyed / block-robots.php
Created February 12, 2015 13:14
PHP: Block Robots using Headers in PHP.
<?php
@header('X-Robots-Tag: "none, noindex, nofollow, noarchive, nosnippet, noodp, notranslate, noimageindex"');
@irazasyed
irazasyed / xss-protection.php
Last active March 5, 2022 01:01
PHP: XSS Protection.
<?php
/* Prevent XSS - Trims and Sanitizes GET/POST Data */
$_GET = array_map(function ($param) {
return strip_tags(trim(addslashes(htmlspecialchars($param))));
}, $_GET);
$_POST = array_map(function ($param) {
return htmlspecialchars(addslashes(trim($param)));
}, $_POST);
@irazasyed
irazasyed / spintax.php
Last active May 21, 2024 08:42
PHP: Text Spinner Class - Nested spinning supported.
<?PHP
/**
* Spintax - A helper class to process Spintax strings.
*/
class Spintax
{
/**
* Set seed to make the spinner predictable.
*/