This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$login = 'user'; | |
$pass = 'userpass'; | |
if (empty($_SERVER['PHP_AUTH_USER']) || | |
$_SERVER['PHP_AUTH_USER'] !== $login || | |
$_SERVER['PHP_AUTH_PW'] !== $pass) { | |
header('WWW-Authenticate: Basic realm="Enter user/userpass as login and password"'); | |
header('HTTP/1.0 401 Unauthorized'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Искать в массиве с помощью пользовательской функции. | |
* Поиск идет до первого не false результата. | |
* @param mixed $needle что ищем | |
* @param array $haystack где ищем | |
* @param callable $callback функция сравнения | |
* @return mixed false или индекс массива | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WPAuth | |
{ | |
private $config; | |
public function __construct(array $config) | |
{ | |
$this->config = array_replace( | |
[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function userLanguage(array $preferred = ['en', 'ru']) | |
{ | |
static $language; | |
// calculate preferred language and do it only once | |
if (!isset($language)) { | |
$language = $preferred[0]; | |
// user has choosen the language | |
if (isset($_COOKIE['lang']) && in_array($_COOKIE['lang'], $preferred)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Parse XML item with attributes. Typically dumped table row. | |
* @param string $buffer XML item | |
* @return array false| array [name => value, ...] | |
*/ | |
function parse_row($buffer) | |
{ | |
$buffer = trim($buffer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_URI} ^/thumb/ | |
RewriteRule ^(.*)$ thumb.php [QSA,L] | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Unroll dot-sequenced keys to new dimension | |
* @param array $source | |
* @return array | |
*/ | |
function deep_load($source) | |
{ | |
$result = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FileHelper | |
{ | |
public static function openAndLock($filename) | |
{ | |
$fh = fopen($filename, 'r+'); | |
if (!$fh || !flock($fh, LOCK_EX)) { | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function file_get_contents_ex($url, $cookie = null, $proxy = null, $auth = null) | |
{ | |
$opts = array( | |
'http' => array( | |
'method' => 'GET', | |
'user-agent'=> 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36', | |
'header' => "Accept-language: en\r\n" . | |
(!empty($auth) ? "Proxy-Authorization: Basic {$auth}\r\n" : '') . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/* | |
* Filter to fill the IP gaps in a MaxMind GeoLite tables. | |
* | |
* For every missing range in the file it puts a dummy one. | |
*/ | |
$types = [ | |
'asnum' => [0, 0, 1, "%s,%s,\"-\"\n"], | |
'blocks' => [2, 0, 1, "\"%s\",\"%s\",\"1\"\n"], |
OlderNewer