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
<?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 | |
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 | |
/** | |
* Искать в массиве с помощью пользовательской функции. | |
* Поиск идет до первого не 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 | |
$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'); |
NewerOlder