js implementation to obtain website search source code
This article mainly shares with you the js implementation of obtaining website search source code. Introducing the following code into all pages can realize the function of collecting system sources. Global unified source information can be used in any page. I hope it can help. Everyone.
var args = { mySite:"localhost", subSite:"子网站,比如移动端: m.xxx.com" } var index = (function(a) { var c = ""; var d = args.mySite; a(function() { var g = function() { return function(k, l, j) { var h = j * 24 * 60 * 60 * 1000; var i = new Date(); i.setTime(i.getTime() + h); var e = "; expires=" + i.toGMTString(); document.cookie = k + "=" + escape(l) + e + "; path=/" } }; try { if (document.referrer.indexOf(d) <= 0 || document.referrer.indexOf(d) > 10) { g().call(window, "regCompanyName", document.referrer.substring(0, 40) + "||" + window.location.href, 30) } } catch (f) { } }); var b = function() { try { if (getCookie) { return getCookie } } catch (f) {} return function(e) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(e + "="); if (c_start != -1) { c_start = c_start + e.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) { c_end = document.cookie.length } return unescape(document.cookie.substring(c_start, c_end)) } } return null } }; })(jQuery); //媒体 var media = ""; //媒体细分 var mediaSubpide = ""; //注册渠道。(直接赋值) var registerChannel = ""; //终端,根据用户使用设备判断 var terminal = ""; //数据来源,根据cookie确定 var dataSource = ""; //当前链接 var localUrl = window.location.href; var userChannel = { //媒体 Media: function(channelInfo){ channelInfo=channelInfo.toLowerCase(); if(channelInfo.indexOf("||") == 0 && (channelInfo.indexOf(args.mySite) >= 0)){ //媒体 无法判断(如直接搜索) media = "网址打开或站内跳转"; //媒体 mediaSubpide = ""; //媒体细分 // 无法获取referrer的来源的情况有: //1、个别平台外链使用noreferrer; //2、https跳转http; //3、网页重定向... //可在外链中植入可判定的参数如www.xxx.com&tag=zhihu if(channelInfo.indexOf("zhihu")>=0){ media = "知乎"; mediaSubpide = ""; } }else if(channelInfo.indexOf("baidu.com") != -1){ media = "百度"; //媒体 if(channelInfo.indexOf('utm_medium=cpc') != -1){ mediaSubpide = "sem"; //媒体细分 }else if(channelInfo.indexOf('utm_medium=cpc') == -1){ mediaSubpide = "seo"; //媒体细分 }else{ mediaSubpide = "其它"; //媒体细分 } }else if(channelInfo.indexOf('haosou.com') != -1 || channelInfo.indexOf('so.com') != -1){ media = "好搜"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf('sogou.com') != -1){ media = "搜狗"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf('sm.cn') != -1){ media = "神马"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf('bing.com') != -1){ media = "必应"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf('google.com') != -1){ media = "google"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf('douban.com') != -1){ media = "豆瓣"; //媒体 mediaSubpide = "无法判断"; //媒体细分 }else if(channelInfo.indexOf("zhihu.com") != -1){ media = "知乎"; mediaSubpide = "无法判断"; } else if(channelInfo.indexOf("toutiao") != -1){ media = "今日头条"; mediaSubpide = "无法判断"; } else{ media = "其它"; //媒体 mediaSubpide = "无法判断"; //媒体细分 } var mediaInfo=new Array(media,mediaSubpide); return mediaInfo; }, //终端 Terminal: function(){ if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))){ terminal = "移动端"; return terminal; }else{ terminal = "PC端"; return terminal; } }, //注册渠道。通过判断当前页面url获取 RegisterChannel: function(){ if(localUrl.indexOf(args.mySite)!= -1 ){ registerChannel = args.mySite+"网站注册"; return registerChannel; }else if(localUrl.indexOf(args.subSite)!= -1){ registerChannel = args.subSite+"网站注册"; return registerChannel; }else{ registerChannel = "未知"; return registerChannel; } } }; //通用设置cookie方法 function setCookie(name, value, days) { var cookieTime = days * 24 * 60 * 60 * 1000; var d = new Date(); d.setTime(d.getTime() + cookieTime); var cookieExpires = "; expires=" + d.toGMTString(); document.cookie = name + "=" + escape(value) + cookieExpires + "; path=/"; } //通用读取cookie方法 function getCookie(name) { var strCookie = document.cookie; var arrCookie = strCookie.split("; "); for (var i = 0; i < arrCookie.length; i++) { var arr = arrCookie[i].split("="); if (arr[0] == name) return unescape(arr[1]); } return ""; } //排除站内跳转的情况,以免window.name被错误覆盖 if(document.referrer.indexOf(args.mySite)<=0){ window.name=document.referrer.substring(0,40)+"||"+window.location.href; } //使用案例 dataSource = getCookie('regCompanyName'); if(!dataSource || ""== dataSource || typeof(dataSource)== "undefined") { //当cookie无法使用时,优先使用window.name dataSource = (window.name) ? window.name : ""; } var judgeMedia = userChannel.Media(dataSource); var judgeTerminal = userChannel.Terminal(); var judgeRegisterChannel = userChannel.RegisterChannel(); console.log(judgeMedia+' ',judgeTerminal+' ',judgeRegisterChannel+' ');
The above is the detailed content of js implementation to obtain website search source code. For more information, please follow other related articles on the PHP Chinese website!

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
