Архив

Архив раздела ‘PHP’
2 ноября 2015 1 комментарий
$LastModified_unix=1234567890;//time()
$LastModified=gmdate("D, d M Y H:i:s \G\M\T",$LastModified_unix);
$IfModifiedSince=false;
if(isset($_ENV['HTTP_IF_MODIFIED_SINCE'])){
	$IfModifiedSince=strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'],5));
}
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
	$IfModifiedSince=strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'],5));
}
if($IfModifiedSince&&$IfModifiedSince>=$LastModified_unix){
	header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
	exit;
}
header('Last-Modified: '.$LastModified);
Categories: PHP Tags:
2 ноября 2015 Нет комментариев

Необходимо настроить 301-й редирект со всех страниц сайта с символами верхнего регистра в URL на аналогичные страницы с нижним регистром.
При этом редирект не должен затрагивать GET параметры после знака «?» в URL.

$url_get=urldecode($_SERVER['REQUEST_URI']);
if(strpos($url_get,'?')!==false){
	$a=explode("?",$url_get);
	$a[0]=mb_strtolower($a[0]);
	$newurl=$a[0]."?".$a[1];
}
else{
	$newurl=mb_strtolower($url_get);
}
if(urldecode($_SERVER['REQUEST_URI'])!=$newurl){
	header('Location: '.$newurl,true,301);
}
Categories: PHP Tags:
9 октября 2015 Нет комментариев

Например разделить строку по латинской X и русской Х.

$exp=preg_split("/(x|х)/",$str);
Categories: PHP Tags:
20 сентября 2015 Нет комментариев
$text=preg_replace('/style=\\"[^\\"]*\\"/','',$text);

http://community.sitepoint.com/t/remove-inline-style-with-preg-replace/21743/2

Categories: PHP Tags:
$arrs=array('_GET','_POST','_COOKIE');
foreach($arrs as $arr_key=>$arr_value){
	if(is_array($$arr_value)){
		foreach($$arr_value as $key=>$value){
			$nbz1=substr_count($value,'--');
			$nbz2=substr_count($value,'/*');
			$nbz3=substr_count($value,"'");
			$nbz4=substr_count($value,'"');
			if($nbz1>0||$nbz2>0||$nbz3>0||$nbz4>0){
				Print404();
				exit(); 
			}
		}
	}
}

http://www.softtime.ru/forum/read.php?id_forum=3&id_theme=83821

Categories: PHP, Web Tags: ,
23 марта 2015 Нет комментариев
$step1=explode('v=',$youtube_link);
$step2=explode('&',$step1[1]);
$video_id=$step2[0];
echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.$video_id.'?autoplay=0" frameborder="0"></iframe>';
Categories: PHP Tags:
26 января 2015 Нет комментариев
strtotime(date('Y-m-01')." -2 month")
Categories: PHP Tags: