cookieの書き込み

phpはsetcookie, jsはdocument.cookie

<?php
setcookie("key1", "value1")
?>
<script>
	document.cookie = 'key2=value2';
</script>

有効期限を設定

<script>
	var key = 'fsa';
	var expire = new Date();
	expire.setTime( expire.getTime() + 1000 * 3600 * 24 * 7);
	document.cookie = 'key=' + encodeURIComponent(key)+ '; path = /sample.php; expires = ' + expire.toUTCString();
</script>