This section provides a tutorial example on how to run multiple script pages that are connected by the session concept. Page outputs prove that the session concept is working.
If you run http://localhost/SessionPage1.php, you should get:
I am buying 3 PHP books.
Next
Counter = 1
Session name = PHPSESSID
Session id = o9oipjgc4r3fqmfk8mlldl5sl5
Contents of $_GET:
Contents of $_POST:
Contents of $_COOKIE:
If you click "Next" on the first page, you will be running http://localhost/SessionPage2.php,
and should get:
I am buying 3 PHP books.
The unit price is 9.99 per book.
Next Prev
Counter = 2
Session name = PHPSESSID
Session id = o9oipjgc4r3fqmfk8mlldl5sl5
Contents of $_GET:
Contents of $_POST:
Contents of $_COOKIE:
PHPSESSID = o9oipjgc4r3fqmfk8mlldl5sl5
If you click "Next" on the second page, you will be running http://localhost/SessionPage3.php,
and should get:
I am buying 3 PHP books.
The unit price is 9.99 per book.
The total price is 29.97.
Prev
Counter = 3
Session name = PHPSESSID
Session id = o9oipjgc4r3fqmfk8mlldl5sl5
Contents of $_GET:
Contents of $_POST:
Contents of $_COOKIE:
PHPSESSID = o9oipjgc4r3fqmfk8mlldl5sl5
As you can see, the session concept is working. Several points should be noted here:
Data can be stored into the session in one page, and retrieve it in another page.
For example, the quantity is stored into the session in the first page, and retrieved
in the second and third page.
The session name is a string defined in the php.ini file.
The session ID is created by PHP, and managed as a cookie.
You can use the session object to manage a count of pages visited in a particular session.
But you can not use the session object to manage a count of pages visited in all sessions.
To manage information across versions, you need a new concept higher than session.
For example, the application and the server concept is higher than the session concept.