How can we register the variables into a session?

How can we register the variables into a session?

A session is a simple and effective way to store information. It works primarily like cookies, where user information is saved. However, unlike a cookie, the information is not stored on the user’s computer, but rather on the server thus making the data safer.

In order for the information to be saved, a session must be started. A new session can be started by using the session_start() function.

A variable can be registered into a session using the $_SESSION function.

For example:

<?php

// Starting session

session_start();


// Storing session data

$_SESSION["firstname"] = "Peter";

$_SESSION["lastname"] = "Parker";

?>

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.