Home  >  Article  >  Backend Development  >  PHP知识分享之session && cookie

PHP知识分享之session && cookie

WBOY
WBOYOriginal
2016-06-23 13:38:29984browse

<?php    /*     * @Content : session && cookie     * @author  : Mr.xml      * @time    : 2015-3-17 09:53:49     */    session_start();    //开启session    header("Content-type:text/html;charset=utf-8");    //设置字符编码    $_SESSION['arr'] = array(        'name' =>'xx',        'age'=>20,        'sex'=>'is_nan',    );    session_destroy();    //销毁session     if(isset($_SESSION)){        print_r($_SESSION);    }else{        echo "session以销毁!";    }///////////////////////////////////////////////////////////////////    // php设置cookie ,php中cookie如何以数组的方式进行存储    $arr  = array(        'name'=>'xxxx22',        'sex'=>'boys',        'age'=>21,    );    //数组转换字符串存储    $cookie  = serialize($arr);    //设置cookie    setcookie('cookies',$cookie,time()+60*60);      print_r($cookies);    setcookie('cookies','',time()-3600)    //销毁cookie    if(isset($cookies)){        print_r($cookies);    }else{        echo "cookie已销毁!";    }

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn