加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP编程:php中将一个对象保存到Session中的方法

发布时间:2020-12-13 02:28:17 所属栏目:PHP教程 来源:网络整理
导读:《php中将一个对象保存到Session中的方法》要点: 本文介绍了php中将一个对象保存到Session中的方法,希望对您有用。如果有疑问,可以联系我们。 PHP编程 本篇章节讲解php中将一个对象保存到Session中的办法.供大家参考研究.具体如下: PHP编程 要保

《php中将一个对象保存到Session中的方法》要点:
本文介绍了php中将一个对象保存到Session中的方法,希望对您有用。如果有疑问,可以联系我们。

PHP编程本篇章节讲解php中将一个对象保存到Session中的办法.分享给大家供大家参考.具体如下:

PHP编程要保存对象到session其实很简单,我们可以使用session_register()函数,下面是使用范例

PHP编程person_class.inc.php如下:

PHP编程
<?php
//
//File: person_class.inc.php
//Contains the class definition necessary to let an object be a session
//variable.
//
class Person
{
  var $name;
  var $email;
  //
  // A simple function to illustrate the point
  //
  function clean_name ()
  {
    $name = preg_replace("/h(.)+/i","1",$this->name);
    return substr($name,15);
  }
}
?>

PHP编程main.php文件如下:

PHP编程
<?php
//
//File: main.php
//Here is where we save and retrieve the object
//
include_once 'person_class.inc.php';
session_register('someperson');
if (!$someperson) {
  $someperson = new Foo;
  $someperson->name = "Item Raja";
  $someperson->email = "itemraja@php.net";
  $someperson->clean_name();
}
?>
<a href="somePage.php">Click Here</a>

PHP编程somPage.php文件如下:

PHP编程
<?php
//
//File: somePage.php
//Print out the name without initializing the
//class and setting the variables
//
include_once 'person_class.inc.php';
session_register('foobar');
print $foobar->name;
?>

PHP编程希望本文所述对大家的php程序设计有所赞助.

欢迎参与《php中将一个对象保存到Session中的方法》讨论,分享您的想法,编程之家 52php.cn为您提供专业教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读