JavaScript для настройки куки - PullRequest
0 голосов
/ 28 марта 2019

Я написал JS-код для настройки файлов cookie, но он не работает, и я не знаю почему.Кто-нибудь может мне помочь?

<html>
<head>
<script>
function setcookie(c_name, cvalue){
var now = now.getDate();
now.setMonth(now.getMonth() +1 )
ex = now.toUTCString();
document.cookie = 'expire day is' + ex+'c_name = ' + c_name +  cvalue

}
function getcookie(c_name)
{
var allcookies = document.cookie
document.write(allcookies)
var spli = allcookies.split(';')
for (i=0 ;i < spli.length; i++){
name = spli[i].split('=')[0];
value = spli[i].split('=')[1];   
document.write('name' +name + 'value'+value)
                         } 
}
function checkcookie() {
username = getCookie(username)
if (username !=null &&  username !=''){
  alert('hello again ' + username)
                           }
else {
username = prompt('ENTER')
alert('heloo' + username)
if (user != "" && user != null) {
setCookie('user',username , 30)
      }
    }     
}
</script>
</head>
<body onload="checkcookie()">

</body>
</html>
...