How to register a variable in PHP session ?

Member

by braeden , in category: Technology , 3 years ago

How to register a variable in PHP session ?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adolf , 3 years ago

In PHP 5.3 or below we can register a variable session_register() function.It is deprecated now and we can set directly a value in $_SESSION Global. 😀


Example usage:

1
2
3
4
5
6
7
8
9
<?php
   // Starting session
    session_start();
   // Use of session_register() is deprecated
    $username = "PhpScots";
    session_register("username");
   // Use of $_SESSION is preferred
    $_SESSION["username"] = "PhpScots";
?>