Lawula ii-cookies nge-PHP kunye ne-JS

Ukusekwa kweicookies zizikripthi zakho okanye zomntu wesithathu kunokulawulwa kakuhle ngoncedo lwe-PHP kunye neJavaScript. Nangona esi ayisosisombululo saneleyo sokuphunyezwa kwezisombululo zecookie emva kwesigwebo senkundla ngokuchasene nePlanethi49 (apha kubalulekile ukuba izixhobo zokulandela umkhondo ezinje ngeGoogle Analytics zingalandeleli kwaye ngenxa yoko zingaseti naziphi iicookies), inokuba sengqiqweni ukuba mhlophe ngokubanzi / uluhlu lwabamnyama cookies.


Oku kulula ukuyenza kwi-PHP: Apha uguqula / ucime naziphi na izihloko zokubekwa kwecookie ezisetiweyo . Ukuba le script ilandelayo ibizwa emva kokuba ii-cookies zilungiselelwe i-header yempendulo ngoncedo lwe- setcookie , iintloko ezingafunekiyo ziya kususwa kwaye ezi cookies azizukubekwa kwasekuqaleni. Ukongeza, ii-cookies ezisetiweyo ngaphambili (umzekelo, ukuba iskripthi sothintelo besingasebenzi nasiphi na isizathu) siyacinywa.

8b723b3329c080e9245028b4d0a3fc64

KwiJavaScript oku kuyinto encinci encinci: Apha sisebenzisa i- Object.defineProperty (ilandela elinamandla ku- __defineGetter__ kunye __defineSetter__ ) ukubhala ngaphezulu iindlela zeetter / setter yento yoxwebhu, esoloko ibizwa xa kusetyenziswa ii-cookies ngoncedo lwe- document.cookie Ufunda aze abhale. Into.getOwnPropertyDescriptor ifumana i-setter / setter yoqobo, apho iseti ibizwa kuphela ukuba ikuki ivunyelwe:

8b723b3329c080e9245028b4d0a3fc64

Emva