<script>
$(function () {
$('form').submit(function( event ) {
var data = $(this).serialize().replace(/[^&]+=&/g, '').replace(/&[^&]+=$/g, '');
$.ajax({
type: 'GET',
url: '/search'+data,
data: data,
success: function(output, status, xhr) {
history.pushState({foo: 'bar'}, 'title', '/search'+data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + thrownError);
}
});
return false;
});
});
</script>
history.pushState({foo: 'bar'}, 'title', this.url);
if (isset($_FILES)){
foreach ($_FILES['uploadfile']['name'] as $k=>$v){
if($_FILES['uploadfile']['type'][$k] == "image/gif" || $_FILES['uploadfile']['type'][$k] == "image/png" || $_FILES['uploadfile']['type'][$k] == "image/jpg" || $_FILES['uploadfile']['type'][$k] == "image/jpeg"){
$blacklist = array(".php", ".phtml", ".php3", ".php4");
foreach ($blacklist as $item){
if(preg_match("/$item\$/i", $_FILES['uploadfile']['name'][$k])){
echo "Нельзя загружать скрипты.";
exit;
}
}
# сюда загружается файл на основном сервере
$file = $_FILES['uploadfile']['tmp_name'][$k];
# адрес сервера
$url = 'http://s1.site.ru/upload.php';
$post = [
'image'=> new CURLFile($file, mime_content_type($file), date('YmdHis').rand(100,1000)),
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
}
}
}
<?php
class Cache
{
private $memcache;
public function __construct()
{
if (extension_loaded('memcache'))
{
$this->memcache = new Memcache();
$this->memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
}
}
public function __destruct()
{
$this->memcache->close();
}
public function save($key, $data, $time = 0)
{
$this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $time);
}
public function load($key)
{
$get_result = $this->memcache->get($key);
return $get_result;
}
public function delete($key)
{
$this->memcache->delete($key);
}
public function clear()
{
$this->memcache->flush();
}
public static function make(Closure $object, $time, $key){
$cache = new Cache();
if (!$cacheData = $cache->load($key)){
$object = is_callable($object) ? call_user_func($object):$object;
$cache->save($key, $object, $time);
return $object;
}
else
{
return $cacheData;
}
}
}
// Cache::make($value, $time, $key);
$data = Cache::make(function(){
return DB::from("users")->orderBy("name DESC")->paginate(28)->fetchAll();
}, 5, md5($_SERVER['REQUEST_URI']) );
function sgp($url, $varname, $value) // substitute get parameter
{
if (is_array($varname)) {
foreach ($varname as $i => $n) {
$v = (is_array($value))
? ( isset($value[$i]) ? $value[$i] : NULL )
: $value;
$url = sgp($url, $n, $v);
}
return $url;
}
preg_match('/^([^?]+)(\?.*?)?(#.*)?$/', $url, $matches);
$gp = (isset($matches[2])) ? $matches[2] : ''; // GET-parameters
if (!$gp) return $url.'?'.$varname.'='.$value;
$pattern = "/([?&])$varname=.*?(?=&|#|\z)/";
if (preg_match($pattern, $gp)) {
$substitution = ($value !== '') ? "\${1}$varname=" . preg_quote($value) : '';
$newgp = preg_replace($pattern, $substitution, $gp); // new GET-parameters
$newgp = preg_replace('/^&/', '?', $newgp);
}
else {
$s = ($gp) ? '&' : '?';
$newgp = $gp.$s.$varname.'='.$value;
}
$anchor = (isset($matches[3])) ? $matches[3] : '';
$newurl = $matches[1].$newgp.$anchor;
return $newurl;
}
<? echo sgp($_SERVER['REQUEST_URI'], 'page', 2);?>
$cur_page + 1;
1+1