What are the advantages of using $_SESSION['name'] = $name; over session_register() in PHP?

Using $_SESSION['name'] = $name; is preferred over session_register() in PHP because session_register() is deprecated as of PHP 5.3.0 and removed in PHP 5.4.0. Using $_SESSION directly is more secure and efficient as it is a superglobal variable. It also makes the code more readable and maintainable.

// Using $_SESSION['name'] = $name; to set session variable
session_start();
$name = "John";
$_SESSION['name'] = $name;