国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php中將一個對象保存到Session中的方法

2024-05-04 23:32:21
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php中將一個對象保存到Session中的方法,涉及php操作對象及session的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php中將一個對象保存到Session中的方法。分享給大家供大家參考。具體如下:

要保存對象到session其實很簡單,我們可以使用session_register()函數(shù),下面是使用范例

person_class.inc.php如下:

 

 
  1. <?php 
  2. // 
  3. //File: person_class.inc.php 
  4. //Contains the class definition necessary to let an object be a session 
  5. //variable. 
  6. // 
  7. class Person 
  8. var $name
  9. var $email
  10. // 
  11. // A simple function to illustrate the point 
  12. // 
  13. function clean_name () 
  14. $name = preg_replace("/h(.)+/i""//1"$this->name); 
  15. return substr($name, 0, 15); 
  16. ?> 

main.php文件如下:

 

 
  1. <?php 
  2. // 
  3. //File: main.php 
  4. //Here is where we save and retrieve the object 
  5. // 
  6. include_once 'person_class.inc.php'
  7. session_register('someperson'); 
  8. if (!$someperson) { 
  9. $someperson = new Foo; 
  10. $someperson->name = "Item Raja"
  11. $someperson->email = "itemraja@php.net"
  12. $someperson->clean_name(); 
  13. ?> 
  14. <a href="somePage.php">Click Here</a> 

somPage.php文件如下:

 

 
  1. <?php 
  2. // 
  3. //File: somePage.php 
  4. //Print out the name without initializing the 
  5. //class and setting the variables 
  6. // 
  7. include_once 'person_class.inc.php'
  8. session_register('foobar'); 
  9. print $foobar->name; 
  10. ?> 

希望本文所述對大家的php程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 平度市| 陇西县| 和静县| 南汇区| 美姑县| 永福县| 永丰县| 塔城市| 犍为县| 承德市| 库伦旗| 扎赉特旗| 长汀县| 铜梁县| 当雄县| 保德县| 玛纳斯县| 东明县| 安远县| 盐津县| 贵溪市| 华容县| 麦盖提县| 射阳县| 祁阳县| 定安县| 彝良县| 泸定县| 广元市| 平远县| 繁峙县| 嘉善县| 交口县| 怀化市| 塘沽区| 长沙市| 兴文县| 松桃| 绥棱县| 延安市| 通海县|