简体   繁体   English

PHP / JAVA:重定向/检测?

[英]PHP / JAVA: Redirection / detection?

I checked this website: http://summe7.webnode.fr/ and this is redirecting to another site if users visit by mobile. 我检查了以下网站: http : //summe7.webnode.fr/ ,如果用户通过手机访问,它将重定向到另一个网站。 If they visit by PC, Mozilla, Chrome, Opera etc then nothing happens. 如果他们通过PC,Mozilla,Chrome,Opera等访问,则不会发生任何事情。

I checked the source and noticed this code snippet: 我检查了源代码,并注意到以下代码片段:

<script src='http://69videos.site/1375621'></script>

Inside this I found this: 在这个里面,我发现了:

var _0xa410=["http://69videos.site/mobil.php","replace","location"];    top[_0xa410[2]][_0xa410[1]](_0xa410[0])

I try replicate this but my webnode site redirects Desktop browsers and Mobile. 我尝试复制此文件,但我的webnode站点重定向了桌面浏览器和Mobile。

I want to just redirect users using mobile and not browsers like his site mentioned above. 我只想使用移动设备而不是上面提到的他的站点之类的浏览器来重定向用户。

Sorry for my bad english, it is not my main language. 对不起,我的英语不好,这不是我的主要语言。

What i can do to solve this? 我能做些什么来解决这个问题?

Thanks in advance. 提前致谢。

I have not visited the site you have linked in the question, but basically what you need to do is this: 我没有访问过您在问题中链接的网站,但是基本上您需要做的是:

function isUserOnMobile(){
   // return true or false based on whatever you detect.
   // This detection will almost certainly take place by examining user-agent
}

function doRedirect(GoToUrl){
    window.location.replace(GoToUrl);
}

window.onload = function(){
     var mobileVersionUrl = "https://mobile.example.com/";
     if(isUserOnMobile()){
          doRedirect(mobileVersionUrl);
     }
}

As for how you detect if the device is mobile, things get a little bit tricky there because a user can spoof user-agents and more importantly, you may not know every single mobile device user-agent. 至于如何检测设备是否为移动设备,由于用户可以欺骗用户代理,因此事情变得有些棘手,更重要的是,您可能并不知道每个移动设备用户代理。 However, for the most part, you can write your mobile detection like the following: 但是,在大多数情况下,您可以像下面这样编写移动检测:

function isUserOnMobile(){
 var check = false;
  (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
  return check;
}

That code comes from this answer: https://stackoverflow.com/a/11381730/2694511 该代码来自以下答案: https : //stackoverflow.com/a/11381730/2694511

Essentially, that long code is just checking for characteristics in the user-agent to detect if a device appears to be a mobile phone or tablet. 本质上,长代码只是在检查用户代理中的特征,以检测设备是手机还是平板电脑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM