Store it in a session or in the query database of each page load?

What is the best way?

Do I have to store the object in the session and transfer it from page to page, or should I query the database every time a user goes to another page in my web application?

If I have to store my object in a session, how would I do it? I tried doing this with serialization and unserialize, but it does not work for me ...

Thanks for any help!

EDIT: Here are some of my code

Page 1:
include "user.php";
session_start();
$user = new user();
$user->$username = "Jason";
$_SESSION["user"] = $user;
header("Location: profile.php");

Page 2:
include "user.php";
session_start();
$user = new user();
$user = $_SESSION["user"];
echo $user->$username;

No results.

+3
source share
2 answers

, . . (, - ).

, , , ( , 10 ). , .

, . raw APC/Memcached, , Cache_Lite Zend_Cache...

+8

:


, / : mecanism ( , - . Sessions).

(APC, memcached, files,...), /unserialize, mecanisms , PHP.

+1

Source: https://habr.com/ru/post/1794804/


All Articles