Considerations when assigning $_SERVER variable to $_SESSION variable in PHP

  question

The following code is saved as test.php

<?php
session_start();
var_dump($_SESSION['test']);
echo '<br />';
$_SESSION['test'] = $_SERVER['PATH_INFO'];
var_dump($_SESSION['test']);
?>
<img src="notice" />

Test this code locally and access the urlhttp://localhost/test.php/a
The value of $_SERVER[‘PATH_INFO’] is’ /a’, and the value of $_SESSION[‘test’] after assignment is’ /a’,After the page refreshes, the output $_SESSION[‘test’] at the beginning of the page should theoretically be’ /a’, but $_SESSION[‘test’] has become’ notice’.

Where the value of notice is the same as that of src in < img src=”notice”/>, and the same value will be output when the value of src is changed to other values.

As shown in the figure:
未命名.jpg

The key is

<img src="notice" />

Php/notice
This triggered test.php.

$_SESSION['test'] = $_SERVER['PATH_INFO']; //此时为notice

So even if you refresh again, the first time you print is notice.