How to store a Session Variable in PHP

The correct way to store and retrieve session variables is to use the PHP $_SESSION variable:

Code for store a session in pHP

<?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>

</body>
</html>

Output:

Pageviews=1

No comments:

Post a Comment