Session function in php

  • Share
  • CevherShare
  • Share

session_start(); is the function should be called in the page, which using session variables. i.e., If session variable is using in a page then we should have to use session_start() function

session_start(); function should be placed before <html> starting tag, it should be present on top of the page.

Here, session variable “value” is created in index.php, then we can use that session “value” in any page of the website.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

session_start();

?>

<html>

<body>

$_SESSION['value']="hai";

echo $_SESSION['value'];

</body>

</html>

 

session_destroy(); is used to destroy all the session variables used in the website.

Thinks to be remembered

If a variable is assigned, without sending to another page we can’t use. But if we have created session variable, then we can use it in any page

prasad

About prasad

Prasad K has written 111 post in this blog.