<code><span><span><?php</span><span>//新增cookie</span> setcookie(<span>'system'</span>,<span>'linux'</span>); <span>//使用cookie</span><span>echo</span><span>$_COOKIE</span>[<span>'system'</span>]; <span>//销毁cookie</span> setcookie(<span>'test'</span>, <span>''</span>, time()-<span>1</span>); <span>//开启session</span> session_start(); <span>//新增session</span><span>$_SESSION</span>[<span>'uname'</span>]=<span>'madao232324'</span>; <span>//使用session</span><span>echo</span><span>'<br>'</span>.<span>$_SESSION</span>[<span>'uname'</span>]; <span>//销毁session</span><span>unset</span>(<span>$_SESSION</span>[<span>'uname'</span>]); <span>//关闭session</span> session_destroy(); </span></code>
以上就介紹了php中cookie和session使用範例,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。