2011-07-07 7 views
4

evercookieで設定したクッキーの価値を得ることは困難です。エバークーシー使用のご質問

私がやりたいことは、名前のついた妖精が設定されているかどうかを確認することです。それが設定されていない場合は、それをsomenumberに設定します。

以下のようになります。 var cookie_value = get_cookie_value; if(cookie_value == notdefined) coookieを "12345"に設定 else PHPコードで使用します。

Eveercoohieの利用コードは例でhttp://samy.pl/evercookie/

var ec = new evercookie(); 

// set a cookie "id" to "12345" 
// usage: ec.set(key, value) 
ec.set("id", "12345"); 

// retrieve a cookie called "id" (simply) 
ec.get("id", function(value) { alert("Cookie value is " + value) }); 

// or use a more advanced callback function for getting our cookie 
// the cookie value is the first param 
// an object containing the different storage methods 
// and returned cookie values is the second parameter 
function getCookie(best_candidate, all_candidates) 
{ 
    alert("The retrieved cookie is: " + best_candidate + "\n" + 
     "You can see what each storage mechanism returned " + 
     "by looping through the all_candidates object."); 

    for (var item in all_candidates) 
     document.write("Storage mechanism " + item + 
      " returned " + all_candidates[item] + " votes<br>"); 
} 
ec.get("id", getCookie); 

// we look for "candidates" based off the number of "cookies" that 
// come back matching since it's possible for mismatching cookies. 
// the best candidate is very-very-likely the correct one 

答えて

1

から以下の通りである、クッキー名が「ID」であるので、ここではあなたがPHPでそれを確認したい方法は次のとおりです。

残念ながら
<?php 
if (isset($_COOKIES['id'])) { 
    //... cookie was set 
} else { 
    //... no cookie was set 
    setcookie('id',$somenumber) ; 
} 
?> 

これは、主要なHTTP cookieを設定するだけで、残りのすべての要素を設定するわけではありません。しかし、次回のリフレッシュ時には、常に要素の1つに値が含まれていることが検出され、他の要素はすべて同じ値に設定されます。

+1

「$ _COOKIES」だけで、もちろん「$ _COOKIES」ではなく、 –

+0

「次回のリフレッシュ時に、evercookieコードはその要素の1つに値が含まれていることを検出し、他のすべての要素を同じ値"それは.set()関数でですか?クライアント側のjavascriptで.set()呼び出しがすべて必要ですか?もしそうなら、クライアント側でどのようなシナリオで.get()を使うのでしょうか? – Doug

関連する問題