2 апреля 2019
Нет комментариев
header('X-XSS-Protection:0');
header('X-XSS-Protection:0');
Например, для замены в $text
{lists_4}
на название списка и список элементов:
preg_match_all("/{lists\s*(.*?)}/si",$text,$matches,PREG_SET_ORDER); if(count($matches)>0){ foreach($matches as $m){ $me=explode('_',trim(trim($m[0],'}'),"{")); if($me[0]=='lists'&&$me[1]>0){ $replace=''; $list=get_by_id($me[1],'lists'); if($list['id']){ $items=get_from_base('*','list_items',"`parent`='".$list['id']."' and `shown`=1",'pos'); if(count($items)>0){ $replace.='<div class="list">'; $replace.='<div class="name">'.$list['name'].'</div>'; $replace.='<ul>'; foreach($items as $count=>$item){ $replace.='<li class="item">'.$item['name'].'</li>'; } $replace.='</ul>'; $replace.='</div>'; } } $text=str_replace($m,$replace,$text); } } }
JS:
$(".input_place").autocomplete({ source:"/?ajax_action=get_places", minLength:4, position:{my:"left top",at:"left bottom"}, select:function(event,ui){ var loc=$(this).closest('form').attr('action'); if(ui.item.country_id){ loc+='?country[]='+ui.item.country_id; $('#hidden_country').val(ui.item.country_id); } if(ui.item.district_id){ loc+='&district[]='+ui.item.district_id; $('#hidden_district').val(ui.item.district_id); } if(ui.item.city_id){ loc+='&city[]='+ui.item.city_id; $('#hidden_city').val(ui.item.city_id); } var selected=ui.item.country_name; if(ui.item.district_name!=''){ selected=ui.item.district_name; } if(ui.item.city_name!=''){ selected=ui.item.city_name; } $(this).val(selected); if($('#hidden_country').val()==undefined){ window.location.href=loc; } return false; } }).autocomplete("instance")._renderItem=function(ul,item){ var li=item.country_name; if(item.district_name!=''){ li+=' '+item.district_name; } if(item.city_name!=''){ li+=' '+item.city_name; } return $("<li>").append(li).appendTo(ul); };
if($_GET['ajax_action']=='get_places'){ $places=array(); $ajax_countries=get_from_base('*','countries',"shown=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `districts` WHERE`shown`=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `cities` WHERE`shown`=1 and `name` LIKE '%".$_GET['term']."%'))))",'pos'); if(count($ajax_countries)>0){ foreach($ajax_countries as $country){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>0,'district_name'=>'','city_id'=>0,'city_name'=>''); $ajax_districts=get_from_base('*','districts',"`parent`=".$country['id']." and `shown`=1 and (`name` LIKE '%".$_GET['term']."%' OR `id` IN (SELECT `parent` FROM `cities` WHERE`shown`=1 and `name` LIKE '%".$_GET['term']."%'))",'pos'); if(count($ajax_districts)>0){ foreach($ajax_districts as $district){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>$district['id'],'district_name'=>$district['name'],'city_id'=>0,'city_name'=>''); $ajax_cities=get_from_base('*','cities',"`parent`=".$district['id']." and `shown`=1 and `name` LIKE '%".$_GET['term']."%'",'pos'); if(count($ajax_cities)>0){ foreach($ajax_cities as $city){ $places[]=array('country_id'=>$country['id'],'country_name'=>$country['name'],'district_id'=>$district['id'],'district_name'=>$district['name'],'city_id'=>$city['id'],'city_name'=>$city['name']); } } } } } } header('Content-Type: application/json'); echo json_encode($places); exit(); }
https://jqueryui.com/autocomplete/#custom-data
if(count($_GET['f'])>0){ reset($_GET['f']); $first_f=key($_GET['f']); echo $first_f; }
function correct_image_orientation($filename,$quality=100){ if(function_exists('exif_read_data')){ $exif=exif_read_data($filename); if($exif&&isset($exif['Orientation'])){ $angles=array(3=>180,6=>270,8=>90); if(isset($angles[$exif['Orientation']])){ $image=imagecreatefromjpeg($filename); $image=imagerotate($image,$angles[$exif['Orientation']],0); imagejpeg($image,$filename,$quality); } } } }
Использование:
move_uploaded_file($file['tmp_name'],ROOT_DIR.IMAGES_PHOTOS_DIR.$fname); correct_image_orientation(ROOT_DIR.IMAGES_PHOTOS_DIR.$fname);
parse_url($_SERVER['HTTP_REFERER'],PHP_URL_HOST)
По умолчанию:
Server => Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16
В /etc/php.ini
expose_php = Off
Результат:
Server => Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
В /etc/httpd/conf/httpd.conf
ServerTokens Prod
Результат:
Server => Apache