How can I store object class into a session in PHP?

后端 未结 4 632
时光取名叫无心
时光取名叫无心 2021-01-19 21:21

How can I have an object class store into PHP session and then get it in my next page as variable. Could you help?

Here is my class.inc.php

class sho         


        
4条回答
  •  庸人自扰
    2021-01-19 21:41

    Once you instantiate the class you can assign it to the session (assuming it's started)

    $_SESSION['SomeShop'] = new Shop();
    
    or 
    
    $Shop = new Shop();
    //stuff
    $_SESSION['SomeShop'] = $Shop;
    

    Keep in mind that wherever you access that object you will need the Shop Class included.

提交回复
热议问题