I need some explanation about php session

Asked By 0 points N/A Posted on -
qa-featured

 

I'm looking for some help regarding PHP sessions,I am new to PHP,

Please anyone can explain me how sessions work,

How do they help us?

SHARE
Best Answer by Beshoy
Answered By 0 points N/A #94431

I need some explanation about php session

qa-featured

PHP application uses sessions and it will be used when a user was in the point where his or her website needs to pass to the user data from a page to another. The usual HTML website do not pass data from a page to other PHP session and this can be resolve by letting the user to store information on the server for future use.

This session is temporary and commonly removed instantly just after the user left the website that utilizes sessions. Session works by making a UID or Unique IDentification number on every visitor and will save variables depending on the ID number.

This way, it can stop two users data from having conflicts with each other when they visits the same webpage.

 

 

 
Best Answer
Best Answer
Answered By 0 points N/A #94432

I need some explanation about php session

qa-featured

When you are working with an application, you open it do some changes and then you close it. This is much like a Session. The computer knows who you are.

It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn't maintain state.

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc).

However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.

Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL

Example:

<?php

session_start();

// store session data

$_SESSION['views']=1;

?>



<html>

<body>



<?php

//retrieve session data

echo "Pageviews=". $_SESSION['views'];

?>



</body>

</html>

Output

Pageviews=1

Thanks

Beshoy

 

Login/Register to Answer

Related Questions