Javascript Code
<script type="text/javascript"> function chk_form(){ var j_keep_login=document.form1.keep_login; var i_username=document.form1.username.value; var i_password=document.form1.password.value; if(j_keep_login.checked==true){ var days=10; // กำหนดจำนวนวันที่ต้องการให้จำค่า var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); document.cookie = "CK_username=" +i_username+ "; expires=" + expires + "; path=/"; document.cookie = "CK_password=" +i_password+ "; expires=" + expires + "; path=/"; }else{ var expires="; expires=Thu, 01 Jan 1970 00:00:01 GMT"; document.cookie = "CK_username="+expires+";-1;path=/"; document.cookie = "CK_password="+expires+";-1;path=/"; } } </script>
PHP Code
<form id="form1" name="form1" method="post" action="" onsubmit="return chk_form()"> ชื่อผู้ใช้ : <input name="username" type="text" id="username" value="<?=$_COOKIE['CK_username']?>" /> <br /> รห้สผ่าน : <input name="password" type="password" id="password" value="<?=$_COOKIE['CK_password']?>" /> <br /> <input name="keep_login" type="checkbox" id="keep_login" value="1" <?=(isset($_COOKIE['CK_username']) && $_COOKIE['CK_username']!="")?"checked":""?> /> จำ้ข้อมูลการล็อกอินไว้<br /> <input type="submit" name="Submit" value="เข้าสู่ระบบ" /> </form>