Sessions in PHP

free php tutorials, php classes, php utilities, free tools

Sessions are great way for storing temporary data about your visitors. Session variables are global variables. Using session, we can collect information entered by user on your web site such as username or password. Session are also used for website statistics that how many visits on website by users?

Session_start();

session_start() function is used for start a session, It is placed before any HTML or PHP code on the top of page. When a PHP session starts, it is randomly generated a session ID, You can view your own session ID by typing $PHPSESSID.

<?php
session_start();
?>
<head>
<head>
<title> ........... </title>
</head>
<body>
<?php
echo "Your session is $PHPSESSID";
?>
</body>
</head>

session_register
session_register is used for register a session variable. see this example session_register has on parameter that is used for varaible, for example:

<?php
session_start();
?>
<head>
<head>
<title> ........... </title>
</head>
<body>
<?php
session_register('name');
$name='Albert';
?>
</body>
</head>

In above example, you have assign a parameter name to session_register, then it will become a global variable $name, and you can assign any value as you wish

Bookmark This Page