Most of websites have no facility to transfer records from a page to the other page. The things which you have checked on one page can be seen on other pages. So, this difficulty has cropped up the need of a different web page.
General idea of Sessions:
Your problem can be solved by using sessions of PHP. But the problem is that this storage is for a short period of time. If your desire is to get the permanent solution of this problem, then you have to find something else.
The way of sessions is different. It saves a specific number for a visitor. This saving is related to the given ID. So, the data of different people can not get mixed.
How to start Session?
It is vital to initialize the session, before saving anything in it. Here is an example for your easiness.
By giving the code, you will be getting registered. You will be given a UID. Now, you can save your data.
Saving a Session Variable
Make an array, if you want to save your data. The array can save as well as recover data.
$_SESSION['views'] = 1;
echo "Pageviews = ". $_SESSION['views']; //Recover data
Pageviews = 1
With the help of this example, we have got to know how to get saved and recovered information.
Use of PHP’s isset function:
You have got to know the way of saving and getting back the data. It is significant to notice whether a session is present or not before going to use it.
This task can be done by isset. The function isset checks the variables whether they are active or not.
We can make a counter of pageview by using isset command. if there is a variable, then we can give it a value and a code to increase the value. Otherwise, we have to make a counter ourselves. Here is a simple example for you.
$_SESSION['views'] = $_SESSION['views']+ 1;
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
If you want to check it then executes it on a recently opened page. You will not get any result as nothing is saved in it. Your “if statement” will get failed. On the other hand, if your statement gets true; the number will get increased.
How to wipe out and delete the session?
The data of session is not permanent. It can get wiped out by itself. Sometimes, you need to remove some data immediately. It can be confidential, related to your business or even to money matters.
All the data will be wiped out by using the function session_destroy.
You have to be careful while using this function. It will delete all the data. Make sure that the data is no more needed.