设置多个cookie值并获取SELECT查询的值

时间:2016-02-29 09:35:14

标签: php mysql cookies

如何在客户结账后在供应商名称中存储供应商名称?

示例:

客户首先检查供应商A的产品并设置cookie,如:

Cookie:
+---------+-------+
|  Name   | Value |
+---------+-------+
| vendors | A, B  |
+---------+-------+

第二次检查供应商B的产品。

SELECT name, paymentinfo FROM vendor WHERE name = (All of cookie values)

然后我希望将所有值的cookie都显示给Already Ordered Vendor Name : A Payment Info : _______________ Vendor Name : B Payment Info : _______________ ,以便显示供应商名称如下:

var url = "https://www.test.com/test.mp4";
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "blob";
request.onload = function (e) {
if (this.status === 200) {
            var file = URL.createObjectURL(this.response);
            var a = document.createElement("a");
            a.href = file;
            a.download = (this.response.name || "file-" + new Date().getTime()) + ".mp4";
            a.id = "downloadVideo";
            document.body.appendChild(a);
            a.click();

            window.addEventListener("focus", refocus, false);
        }
    };
    request.send();

当所有cookie过期时,它将不会显示任何内容。

1 个答案:

答案 0 :(得分:0)

您应该使用循环来遍历Cookie并获取值。然后只需读取值并将它们传递给您的逻辑。我添加了一些javascript函数,它们只是将它们复制粘贴到项目中并使用它们。他们应该让你去,因为我不清楚你的问题。

    function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();

    document.cookie = cname + "=" + cvalue + "; " + expires + "; ";
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}

function editCookie(cname4,cVal){
    setCookie(cname4,cVal,365);

}


function checkOrSetCookie(cname2, cdata) {
   var cookie = getCookie(cname2);
   var rVal;
    if (cookie != "") {
       rVal=true;

    } else {

        if (cdata != "" && cdata != null) {
            setCookie(cname2, cdata, 365);

        }else{
            rVal=false;

        }
    }
}

function deleteCookie(cname3){
    document.cookie = cname3+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
function deleteAllCookies() {

    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}