I have some function (pasted below little piece of function), which I used as separate function and it worked well.
Now I want to move this functon into some class. As you see, it works with $_SESSION and $_COOKIE.
Question is, is it required to send $_SESSION and $_COOKIE as input data while calling this function (I mean something like that: calling like protect($_SESSION, $_COOKIE) and then fetch them from inside function)? or it will work without sending them?
...
public function protect() {
session_start();
if (isset($_SESSION['HTTP_USER_AGENT'])) {
if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) {
$this->logout();
exit;
}
}
if (!isset($_SESSION['id']) && !isset($_SESSION['login'])) {
if (isset($_COOKIE['id']) && isset($_COOKIE['key'])) {
...
$_COOKIEand$_SESSIONare superglobals, which means they are available everywhere. You never need to import them, pass them as arguments or anything similar, they are always available in any scope.For this reason, they should always be treated as read-only – assigning a new value to them will affect the rest of the scripts execution in every scope.