쿠키(cookie) Sample

<?php
/**
 * Cookie helper
 *
 * Created on 2011. 11. 18.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package helper
 * @subpackage controllers
 * @version 1.0
 */
class Cookie_hlp extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		
		// Cookie Helper Load
		$this->load->helper('cookie');
		// Url Helper Load
		$this->load->helper('url');
	}
	
	function index() {
		$data['cookie'] = get_cookie('test');
		$this->load->view('cookie_hlp_sample', $data);
	}
	
	function set() {
		set_cookie('test', $this->input->post('user_data'), 3600);
		redirect('cookie_hlp');
	}
	
	function del() {
		delete_cookie('test');
		redirect('cookie_hlp');
	}
}
<?php $this->load->view('inc/header')?>

<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th style="text-align:center" colspan="2">Cookie Helper</th>
</tr>
</thead>
<form method="post" action="<?=site_url('cookie_hlp/set')?>">
<tr>
	<td>set_cookie()</td>
	<td><input type="text" name="user_data" value="<?php echo time()?>_userdata" /> <input type="submit" value="set Cookie" /></td>
</tr>
</form>
<tr>
	<td>delete_cookie()</td>
	<td><input type="button" value="delete Cookie" onclick="document.location.href = '<?=site_url('cookie_hlp/del')?>'" /></td>
</tr>
<thead>
<tr>
  <th style="text-align:center" width="20%">구분</th>
  <th width="80%">결과</th>
</tr>
</thead>
<tr>
	<td>get_cookie('test')</td>
	<td><?=get_cookie('test')?></td>
</tr>
</table>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0155 seconds)