PHP

쿠키로 아이디 저장하는 방법

0hee 2008. 11. 18. 08:58
login.html

<?
if($_COOKIE["cookie_id"]) {
 $checked = "checked";
   $focus = "id";
} else {
 $checked = "";
   $focus = "password";
}
?>

<table cellSpacing="0" height=80% cellPadding="0" width=100% border="0">
<form method='post' name='form1' action="login_ok.php" onSubmit="return checkForm();">
 <tr>
  <td valign=middle align=center>
 
  <table width=345 border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td style=padding-left:8px;padding-bottom:5px><img src=img/login_logo.gif></td>
    </tr>
  </table>
  <table width=340  border="0" cellspacing="0" cellpadding="0" background=img/bg_login2.gif>
    <tr>
      <td width=7><img src=img/login_left.gif></td>
      <td>
        <table width=100% border="0" cellspacing="3" cellpadding="0">
          <tr>
            <td width=100 align=right><img src=img/text_id.gif></td>
            <td><input type='text' name='id' value="<?=$_COOKIE["cookie_id"]?>" style=width:110px;height:20px; class=input>
               <input type=checkbox name=remember_id value=1 <?=$checked?>>아이디기억하기</td>
               </td>
          </tr>
          <tr>
            <td align=right><img src=img/text_pw.gif></td>
            <td><input type='password' name='password' value="" style=width:110px;height:20px;  class=input></td>
          </tr>
        </table>
      </td>
      <td  width=95><input type='image' src="./img/btn_login.gif" name="login" border="0" tabindex="3" style="cursor:pointer;"></td>
      <td width=7><img src=img/login_right.gif></td>
    </tr>
  </table>



login_ok.php

if($remember_id){
$cookie_id = $id;
setcookie('cookie_id',$cookie_id,time()+864000,'/');
}else{
setcookie('cookie_id','',0,'/');
}     
@session_start();