Hi, I'm a beginner of JavaScript.

I need the code for creating pgv_pvid and ssid.


I had searched the web, and got some code, I wonder if the code is right:

var curDate = new Date();
var curMs = curDate.getUTCMilliseconds();
pgv_pvid = (Math.round(Math.random() * 2147483647) * curMs) % 10000000000;
ssid = "s" + (Math.round(Math.random() * 2147483647) * curMs) % 10000000000;
WScript.Echo(pgv_pvid)
WScript.Echo(ssid)

js file:

(function() {
    var _d,
    _l,
    _b,
    _n = "-",
    _params,
    _curDomain,
    _curUrl,
    _domainToSet,
    _refDomain,
    _refUrl,
    _image,
    _ver = "3.0.2";
    if (typeof(_rep) == "undefined") {
        var _rep = 1
    }
    function tcss(params) {
        this.url = [];
        this.init(params)
    }
    tcss.prototype = {
        init: function(params) {
            params ? _params = params: _params = {};
            _d = document;
            if (! (_params.statIframe)) {
                if (window != top) {
                    try {
                        _d = top.document
                    } catch(e) {}
                }
            }
            _l = _d.location;
            _b = _d.body
        },
        run: function() {
            var bt,
            et,
            ext;
            bt = new Date().getTime();
            _cookie.init();
            this.url.push(this.getDomainInfo());
            this.url.unshift("http://pingfore." + _domainToSet + "/pingd?");
            this.url.push(this.getRefInfo(_params));
            try {
                if (navigator.cookieEnabled) {
                    this.url.push("&pvid=" + _cookie.setCookie("pgv_pvid", true))
                } else {
                    this.url.push("&pvid=NoCookie")
                }
            } catch(e) {
                this.url.push("&pvid=NoCookie")
            }
            this.url.push(this.getMainEnvInfo());
            this.url.push(this.getExtendEnvInfo());
            this.url.push("&vs=" + _ver);
            if (_params.userDefineVariable) {
                this.url.push(_udv.setv(_params.userDefineVariable))
            } else {
                this.url.push(_udv.setv())
            }
            _cookie.setCookie("ssid");
            _cookie.save();
            if (_params.originalReferer) {
                this.url.push("&or=" + _params.originalReferer)
            }
            et = new Date().getTime();
            _params.extParam ? ext = _params.extParam + "|": ext = "";
            this.url.push("&ext=" + escape(ext + (et - bt)));
            this.url.push("&reserved1=" + escape(_params.reserved1Param || ""));
            this.url.push("&rand=" + Math.round(Math.random() * 100000));
            this.sendInfo(this.url.join(""));
            if (_params.hot) {
                if (document.attachEvent) {
                    document.attachEvent("onclick", this.watchClick)
                } else {
                    document.addEventListener("click", this.watchClick, false)
                }
            }
            if (_params.repeatApplay && _params.repeatApplay == "true") {
                if (typeof(_rep) != "undefined") {
                    _rep = 1
                }
            }
        },
        getDomainInfo: function(hot) {
            var dm,
            url;
            _curDomain = dm = _params.virtualDomain || _l.host;
            dm = _curDomain.toLowerCase();
            if (!_domainToSet) {
                _domainToSet = this.getCookieSetDomain()
            }
            if (hot) {
                var pl = dm.indexOf(":");
                if (pl > -1) {
                    dm = dm.substr(0, pl) + ".hot" + dm.substr(pl)
                } else {
                    dm += ".hot"
                }
            }
            url = this.getCurrentUrl();
            return ("dm=" + dm + "&url=" + url)
        },
        getCurrentUrl: function() {
            var url = "";
            var arg = _n;
            if (_params.virtualURL) {
                url = _params.virtualURL
            } else {
                url = _curUrl = escape(_l.pathname);
                if (_l.search != "") {
                    arg = escape(_l.search.substr(1))
                }
                if (_params.senseParam) {
                    var value = this.getParameter(_params.senseParam, _d.URL);
                    if (value) {
                        url += "_" + value
                    }
                }
            }
            return url + "&arg=" + arg
        },
        getRefInfo: function(params) {
            var refdm = _n,
            refurl = _n,
            refarg = _n,
            refStr = _d.referrer,
            tagParamName,
            adtag,
            pos;
            var virtualDomain = params.virtualDomain ? params.virtualDomain: _n;
            var virtualURL = params.virtualURL ? params.virtualURL: _n;
            _refDomain = params.virtualRefDomain ? params.virtualRefDomain: "";
            _refUrl = params.virtualRefURL ? params.virtualRefURL: "";
            if (params.statIframe || params.useCookie == "true") {
                refStr = _cookie.get("pgvReferrer");
                var newRef = _d.URL;
                var paraPos = newRef.indexOf("?");
                if (paraPos > -1) {
                    newRef = newRef.substr(0, paraPos)
                }
                _cookie.set("pgvReferrer", newRef)
            } else {
                if (params.useCookie == "set" && _refDomain != "" && _refUrl != "") {
                    var newRef = (("https:" == _l.protocol) ? "https://": "http://");
                    newRef += _refDomain + refUrl;
                    _cookie.set("pgvReferrer", newRef)
                } else {
                    if (params.useCookie == "set" && (virtualDomain != _n || virtualURL != _n)) {
                        var newRef = (("https:" == _l.protocol) ? "https://": "http://");
                        newRef += virtualDomain == _n ? _curDomain: virtualDomain;
                        newRef += virtualURL == _n ? _curUrl: virtualURL;
                        _cookie.set("pgvReferrer", newRef)
                    } else {
                        if (params.useCookie == "get") {
                            var oldRef = _cookie.get("pgvReferrer");
                            if (oldRef != "") {
                                refStr = oldRef
                            }
                            _cookie.set("pgvReferrer", "")
                        } else {
                            _cookie.set("pgvReferrer", "")
                        }
                    }
                }
            }
            tagParamName = params.tagParamName || "ADTAG";
            adtag = this.getParameter(tagParamName, _d.URL);
            if (adtag) {
                refdm = "ADTAG";
                refurl = adtag
            }
            pos = refStr.indexOf("://");
            if (pos > -1 && refdm == _n) {
                var re = /(\w+):\/\/([^\:|\/]+)(\:\d*)?(.*\/)([^#|\?|\n]+)?(#.*)?(\?.*)?/i;
                var arr = refStr.match(re);
                if (arr) {
                    refdm = arr[2];
                    refurl = arr[4] + arr[5]
                }
            }
            if (refStr.indexOf("?") != -1) {
                var pos = refStr.indexOf("?") + 1;
                refarg = refStr.substr(pos)
            }
            if (_refDomain != "" && params.useCookie == "false") {
                refdm = _refDomain
            }
            if (_refUrl != "" && params.useCookie == "false") {
                refurl = _refUrl
            }
            _refDomain = refdm;
            _refUrl = escape(refurl);
            return ("&rdm=" + _refDomain + "&rurl=" + _refUrl + "&rarg=" + escape(refarg))
        },
        getMainEnvInfo: function() {
            var ret = "";
            try {
                var scr = _n,
                scl = _n,
                lang = _n,
                cpuc = _n,
                pf = _n,
                tz = _n,
                java = 0,
                n = navigator;
                if (self.screen) {
                    scr = screen.width + "x" + screen.height;
                    scl = screen.colorDepth + "-bit"
                }
                if (n.language) {
                    lang = n.language.toLowerCase()
                } else {
                    if (n.browserLanguage) {
                        lang = n.browserLanguage.toLowerCase()
                    }
                }
                java = n.javaEnabled() ? 1: 0;
                cpuc = n.cpuClass;
                pf = n.platform;
                tz = new Date().getTimezoneOffset() / 60;
                ret = "&scr=" + scr + "&scl=" + scl + "&lang=" + lang + "&java=" + java + "&cc=" + cpuc + "&pf=" + pf + "&tz=" + tz
            } catch(e) {} finally {
                return ret
            }
        },
        getExtendEnvInfo: function() {
            var ret = "";
            try {
                var flash,
                currentUrl = _l.href,
                connectType = _n;
                ret += "&flash=" + this.getFlashInfo();
                if (_b.addBehavior) {
                    _b.addBehavior("#default#homePage");
                    if (_b.isHomePage(currentUrl)) {
                        ret += "&hp=Y"
                    }
                }
                if (_b.addBehavior) {
                    _b.addBehavior("#default#clientCaps");
                    connectType = _b.connectionType
                }
                ret += "&ct=" + connectType
            } catch(e) {} finally {
                return ret
            }
        },
        getFlashInfo: function() {
            var f = _n,
            n = navigator;
            try {
                if (n.plugins && n.plugins.length) {
                    for (var i = 0; i < n.plugins.length; i++) {
                        if (n.plugins[i].name.indexOf("Shockwave Flash") > -1) {
                            f = n.plugins[i].description.split("Shockwave Flash ")[1];
                            break
                        }
                    }
                } else {
                    if (window.ActiveXObject) {
                        for (var i = 12; i >= 5; i--) {
                            try {
                                var fl = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");
                                if (fl) {
                                    f = i + ".0";
                                    break
                                }
                            } catch(e) {}
                        }
                    }
                }
            } catch(e) {}
            return f
        },
        getParameter: function(name, src) {
            if (name && src) {
                var r = new RegExp("(\\?|#|&)" + name + "=([^&^#]*)(#|&|$)");
                var m = src.match(r);
                return m ? m[2] : ""
            }
            return ""
        },
        getCookieSetDomain: function() {
            var dotlen,
            pos,
            domainToSet,
            dot = [],
            j = 0;
            for (var i = 0; i < _curDomain.length; i++) {
                if (_curDomain.charAt(i) == ".") {
                    dot[j] = i;
                    j++
                }
            }
            dotlen = dot.length;
            pos = _curDomain.indexOf(".cn");
            if (pos > -1) {
                dotlen--
            }
            domainToSet = "qq.com";
            if (dotlen == 1) {
                domainToSet = _curDomain
            } else {
                if (dotlen > 1) {
                    domainToSet = _curDomain.substring(dot[dotlen - 2] + 1)
                }
            }
            return domainToSet
        },
        watchClick: function(e) {
            try {
                var istag = true,
                hottag = "",
                srcElement;
                srcElement = e.target || window.event.srcElement;
                switch (srcElement.tagName) {
                case "A":
                    hottag = "<A href=" + srcElement.href + ">" + srcElement.innerHTML + "</a>";
                    break;
                case "IMG":
                    hottag = "<IMG src=" + srcElement.src + ">";
                    break;
                case "INPUT":
                    hottag = "<INPUT type=" + srcElement.type + " value=" + srcElement.value + ">";
                    break;
                case "BUTTON":
                    hottag = "<BUTTON>" + srcElement.innerText + "</BUTTON>";
                    break;
                case "SELECT":
                    hottag = "SELECT";
                    break;
                default:
                    istag = false;
                    break
                }
                if (istag) {
                    var t = new tcss(_params);
                    var pos = t.getElementPos(srcElement);
                    if (_params.coordinateId) {
                        var coordinatePos = t.getElementPos(document.getElementById(_params.coordinateId));
                        pos.x -= coordinatePos.x
                    }
                    t.url.push(t.getDomainInfo(true));
                    t.url.push("&hottag=" + escape(hottag));
                    t.url.push("&hotx=" + pos.x);
                    t.url.push("&hoty=" + pos.y);
                    t.url.push("&rand=" + Math.round(Math.random() * 100000));
                    t.url.unshift("http://pinghot." + _domainToSet + "/pingd?");
                    t.sendInfo(t.url.join(""))
                }
            } catch(ex) {}
        },
        getElementPos: function(el) {
            if (el.parentNode === null || el.style.display == "none") {
                return false
            }
            var ua = navigator.userAgent.toLowerCase(),
            parent = null,
            pos = [],
            box;
            if (el.getBoundingClientRect) {
                var scrollTop,
                scrollLeft,
                clientTop,
                clientLeft;
                box = el.getBoundingClientRect();
                scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
                scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
                clientTop = document.body.clientTop;
                clientLeft = document.body.clientLeft;
                return {
                    x: box.left + scrollLeft - clientLeft,
                    y: box.top + scrollTop - clientTop
                }
            } else {
                if (document.getBoxObjectFor) {
                    box = document.getBoxObjectFor(el);
                    var borderLeft = (el.style.borderLeftWidth) ? Math.floor(el.style.borderLeftWidth) : 0;
                    var borderTop = (el.style.borderTopWidth) ? Math.floor(el.style.borderTopWidth) : 0;
                    pos = [box.x - borderLeft, box.y - borderTop]
                } else {
                    pos = [el.offsetLeft, el.offsetTop];
                    parent = el.offsetParent;
                    if (parent != el) {
                        while (parent) {
                            pos[0] += parent.offsetLeft;
                            pos[1] += parent.offsetTop;
                            parent = parent.offsetParent
                        }
                    }
                    if (ua.indexOf("opera") > -1 || (ua.indexOf("safari") > -1 && el.style.position == "absolute")) {
                        pos[0] -= document.body.offsetLeft;
                        pos[1] -= document.body.offsetTop
                    }
                }
            }
            if (el.parentNode) {
                parent = el.parentNode
            } else {
                parent = null
            }
            while (parent && parent.tagName != "BODY" && parent.tagName != "HTML") {
                pos[0] -= parent.scrollLeft;
                pos[1] -= parent.scrollTop;
                if (parent.parentNode) {
                    parent = parent.parentNode
                } else {
                    parent = null
                }
            }
            return {
                x: pos[0],
                y: pos[1]
            }
        },
        sendClick: function() {
            if (_params.hottag) {
                this.url.push(this.getDomainInfo(true));
                this.url.push("&hottag=" + escape(_params.hottag));
                this.url.push("&hotx=9999&hoty=9999");
                this.url.push("&rand=" + Math.round(Math.random() * 100000));
                this.url.unshift("http://pinghot." + _domainToSet + "/pingd?");
                this.sendInfo(this.url.join(""))
            }
        },
        sendInfo: function(url) {
            _image = new Image(1, 1);
            _image.src = url
        }
    };
    var _udv = {
        vscope: {
            page: 3,
            session: 2,
            user: 1
        },
        setv: function(tuple) {
            var params = "";
            var val = "";
            if (!tuple || !tuple.name || tuple.name == "" || !tuple.value || tuple.value == "" || !tuple.scope || tuple.scope < 1 || tuple.scope > 3) {
                val = _cookie.get("custvar=") == _n ? _cookie.get("custvar=", true) : _cookie.get("custvar=");
                params = "&custvar=" + val
            } else {
                var val = tuple.name + ":" + tuple.value;
                switch (tuple.scope) {
                case this.vscope.page:
                    break;
                case this.vscope.session:
                    _cookie.setCookie("custvar", false, val);
                    break;
                case this.vscope.user:
                    _cookie.setCookie("custvar", true, val);
                    break
                }
                params = "&custvar=" + val
            }
            return params
        }
    };
    var _cookie = {
        sck: [],
        sco: {},
        init: function() {
            var value = this.get("pgv_info=", true);
            if (value != _n) {
                var arr = value.split("&");
                for (var i = 0; i < arr.length; i++) {
                    var arr2 = arr[i].split("=");
                    this.set(arr2[0], unescape(arr2[1]))
                }
            }
        },
        get: function(name, isend) {
            var cookies = isend ? _d.cookie: this.get("pgv_info=", true);
            var value = _n;
            var offset,
            end;
            offset = cookies.indexOf(name);
            if (offset > -1) {
                offset += name.length;
                end = cookies.indexOf(";", offset);
                if (end == -1) {
                    end = cookies.length
                }
                if (!isend) {
                    var end2 = cookies.indexOf("&", offset);
                    if (end2 > -1) {
                        end = Math.min(end, end2)
                    }
                }
                value = cookies.substring(offset, end)
            }
            return value
        },
        set: function(key, value) {
            this.sco[key] = value;
            var isExist = false;
            var sckLen = this.sck.length;
            for (var i = 0; i < sckLen; i++) {
                if (key == this.sck[i]) {
                    isExist = true;
                    break
                }
            }
            if (!isExist) {
                this.sck.push(key)
            }
        },
        setCookie: function(name, isend, value) {
            var id = _cookie.get(name + "=", isend);
            if (id == _n && !value) {
                isend ? id = "": id = "s";
                var curDate = new Date();
                var curMs = curDate.getUTCMilliseconds();
                id += (Math.round(Math.abs(Math.random() - 1) * 2147483647) * curMs) % 10000000000
            } else {
                id = value ? value: id
            }
            if (isend) {
                this.saveCookie(name + "=" + id, "expires=Sun, 18 Jan 2038 00:00:00 GMT;")
            } else {
                this.set(name, id)
            }
            return id
        },
        save: function() {
            if (_params.sessionSpan) {
                var expires = new Date();
                expires.setTime(expires.getTime() + (_params.sessionSpan * 60 * 1000))
            }
            var cookies = "";
            var sckLen = this.sck.length;
            for (var i = 0; i < sckLen; i++) {
                cookies += this.sck[i] + "=" + this.sco[this.sck[i]] + "&"
            }
            cookies = "pgv_info=" + cookies.substr(0, cookies.length - 1);
            var expire = "";
            if (expires) {
                expire = "expires=" + expires.toGMTString()
            }
            this.saveCookie(cookies, expire)
        },
        saveCookie: function(cookie, expires) {
            _d.cookie = cookie + ";path=/;domain=" + _domainToSet + ";" + expires
        }
    };
    window.pgvMain = function(param1, param2) {
        var params = "";
        if (param2) {
            params = param2;
            _ver = "o3.0.2"
        } else {
            params = param1;
            _ver = "3.0.2"
        }
        try {
            if (_rep == 1) {
                _rep = 2
            } else {
                return
            }
            new tcss(params).run()
        } catch(e) {}
    };
    window.pgvSendClick = function(params) {
        new tcss(params).sendClick()
    };
    window.pgvWatchClick = function(params) {
        new tcss(params).watchClick()
    }
})();

Yes, your first post is correct. On the second block of code you posted, upon first visit of the page that contains said code, pgv_pvid is set to some value
and ssid gets that same value but prefixed with an "s". However, upon subsequent visits, the value is obtained from the cookie if it exists, rather than creating a new value for pgv_pvid.

In your case, based on lines 5 and 6 of your first block of code, subsequent runs/executions of your js script will end up creating a new value every time. If you want your program to "remember" the previous value, you will need to save it onto a file or a database along with a time stamp so you know when it should expire.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.