深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 639|回复: 2
打印 上一主题 下一主题

Radphp的session处理

[复制链接]

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
跳转到指定楼层
楼主
发表于 2020-9-2 13:41:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
restore_session 用于清空

  1. /**
  2. * Shutdown function, called by the PHP engine as the last thing to do before shutdown.
  3. *
  4. * This function is automatically called by the PHP engine just before shutdown, and it's the right moment to serialize
  5. * all components as no more user code is going to be executed.
  6. *
  7. * This way, the status of all objects in the aplication is stored to be recovered later without user intervention.
  8. *
  9. * @see Application::serializeChildren()
  10. * @link [url]http://www.php.net/manual/en/function.register-shutdown-function.php[/url]
  11. *
  12. */
  13. function RPCLShutdown()
  14. {
  15.         global $application;

  16.         //This is the moment to store all properties in the session to retrieve them later
  17.         $application->serializeChildren();

  18.         //Uncomment this to get what is stored on the session at the last step of your scripts
  19.         /*
  20.         echo "<pre>";
  21.         print_r($_SESSION);
  22.         echo "</pre>";
  23.         */
  24. }
复制代码


回复

使用道具 举报

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
沙发
 楼主| 发表于 2020-9-2 13:46:33 | 只看该作者
class Application extends Component


  1.        function __construct($aowner=null)
  2.         {
  3.                 parent::__construct($aowner);

  4.                 global $startup_functions;

  5.                 //Call all startup functions before create the session
  6.                 reset($startup_functions);
  7.                 while(list($key, $val)=each($startup_functions))
  8.                 {
  9.                         $val();
  10.                 }

  11.                 if(!isset($_SESSION))
  12.                 {
  13.                   if (!session_start()) die ("Cannot start session!");
  14.                 }

  15.                 if (isset($_GET['restore_session']))
  16.                 {
  17.                         if (!isset($_POST['xajax']))
  18.                         {
  19.                             $_SESSION = array();
  20.                             session_destroy();
  21.                             if (!session_start()) die ("Cannot start session!");
  22.                         }
  23.                 }

  24.                 //TODO: Check this for security issues
  25.                 reset($_GET);
  26.                 while (list($k,$v)=each($_GET))
  27.                 {
  28.                         if (strpos($k,'.')===false) $_SESSION[$k]=$v;
  29.                 }
  30.         }
复制代码


回复 支持 反对

使用道具 举报

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
板凳
 楼主| 发表于 2020-9-2 13:48:08 | 只看该作者
  1.         function serialize()
  2.         {
  3.             $toserialize=array();
  4.             reset($this->components->items);
  5.             while (list($k,$v)=each($this->components->items))
  6.             {
  7.                 $parent="";
  8.                 if ($v->inheritsFrom('Control')) $parent=$v->parent->Name;

  9.                 if ($v->Name!='') $toserialize[$v->Name]=array($parent,$v->className());
  10.             }

  11.                 global $application;

  12.                 $_SESSION['comps.'.$application->Name.'.'.$this->className()]=$toserialize;

  13.                 //Store last resource read to prevent reloading again in the next post
  14.                 $_SESSION[$this->readNamePath().'._reallastresourceread']=$this->reallastresourceread;
  15.                 parent::serialize();
  16.         }
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-4 20:51 , Processed in 0.033956 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表