PHP会话未按预期工作

I am having problems getting PHP sessions to work correctly. I have the following two pages as a test. I would expect sess2.php to output 'bing' but it isn't doing.

sess1.php

<?php
session_start();
$_SESSION['usr'] = 'bing';
echo '<a href="sess2.php">go</a>';

sess2.php

<?php
session_start();
echo $_SESSION['usr'];

Am I missing something?

has the var/lib/php/session folder writte permisions?

Sometimes the user / group executing apache are not the same as the root or your owner user/group, that's depending on specific built in configuration.

Try to chmod 777 to your session storage path , you can perform it doing session_save_path()  to see the specific folder or look in your phpinfo()

Try to modify files like this to see where the problem is:

sess1.php

<?php
session_start();
$_SESSION['usr'] = 'bing';
echo '<a href="sess2.php">go</a>';
echo '<pre>' . print_r($_SESSION, true) . '</pre>'

sess2.php

<?php
session_start();
echo '<pre>' . print_r($_SESSION, true) . '</pre>'

If you see an empty $_SESSION at sess1.php then the problem with opening and/or setting session itself; if sess1.php is fine, but sess2.php has empty $_SESSION then something wrong with passing session across requests (e.g. disabled cookies). Either way this will give you a clue on where the problem is and figure out solution from there.