建议楼主看看手册session那部分,写得很详细,楼主的问题都在里面有解答

解决方案 »

  1.   

    1:/********session用法************/
    <?php
    /****page1****/
    session_start();
    $_SESSION['YourNamed1'] = 'green';
    $_SESSION['YourNamed2'] = 'cat';
    $_SESSION['YourNamed3'] = time();
    ?>
    <?php
    /****page2****/
    echo $_SESSION['YourNamed1'];//可直接引用,其它类似;
    ?>
    /************安全方面(手册上的)****************/
    Sessions and security
    External links: Session fixation The session module cannot guarantee that the information you store in a session is only viewed by the user who created the session. You need to take additional measures to actively protect the integrity of the session, depending on the value associated with it. Assess the importance of the data carried by your sessions and deploy additional protections -- this usually comes at a price, reduced convenience for the user. For example, if you want to protect users from simple social engineering tactics, you need to enable session.use_only_cookies. In that case, cookies must be enabled unconditionally on the user side, or sessions will not work. There are several ways to leak an existing session id to third parties. A leaked session id enables the third party to access all resources which are associated with a specific id. First, URLs carrying session ids. If you link to an external site, the URL including the session id might be stored in the external site's referrer logs. Second, a more active attacker might listen to your network traffic. If it is not encrypted, session ids will flow in plain text over the network. The solution here is to implement SSL on your server and make it mandatory for users.
      

  2.   

    Session 变量:$_SESSION
    注: 在 PHP 4.1.0 及以后版本使用。之前的版本,使用 $HTTP_SESSION_VARS。 包含当前脚本中 session 变量的数组。参阅 Session 函数文档以获得更多信息。 这是一个“superglobal”,或者可以描述为自动全局变量。这只不过意味这它在所有的脚本中都有效。在函数或方法中不需要使用 global $_SESSION; 来访问它,就如同使用 $HTTP_SESSION_VARS 一样。 $HTTP_SESSION_VARS 包含着同样的信息,但是不是一个自动全局变量(请注意 PHP 是把 $HTTP_SESSION_VARS 和 $_SESSION 这两个变量当作不同的变量来处理的)。 如果设置了 register_globals 指令,这些变量也在所有脚本中可用;也就是,分离了 $_SESSION 和 $HTTP_SESSION_VARS 数组。相关信息,请参阅安全的相关章节使用 Register Globals。这些单独的全局变量不是自动全局变量。
    /*******自己可在网上再GO一下*********/
      

  3.   

    我定义了"sess_open()","sess_close()","sess_read()","sess_write()","sess_destroy()","sess_gc()"这些函数后
    执行session_set_save_handler("sess_open","sess_close","sess_read","sess_write","sess_destroy","sess_gc") or die("error:");  
    运行后输出了"error:",
    继续
    session_start();  
    $_SESSION["count1"]="test";
    结果数据库还是没有改变。
    但是不知道哪里错了。。
      

  4.   

    Write and Close handlers are called after destructing objects since PHP 5.0.5. Thus destructors can use sessions but session handler can't use objects. In prior versions, they were called in the opposite order. It is possible to call session_write_close() from the destructor to solve this chicken and egg problem.
      

  5.   

    session_set_save_handler()之前要先
    session_write_close()