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

PHP知识分享之session && cookie

WBOY
Release: 2016-06-23 13:38:29
Original
1000 people have browsed it

<?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已销毁!";    }
Copy after login

 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template