Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - SESSION not registering

Tags:

php

I tried to make admin panel and I am using sessions , but have problem, session does not work,

index.php

$r=mysql_fetch_array($result);
$login=$r["login"];
session_register('login');
Header("Location: protected.php");

protected.php

<?php 
session_start();
if (!isset($_SESSION['login'])) { 
  echo "Not work";
}
else{
  echo "Work";
}
?>

I do not know what the problem is, because in index.php I register session, but in protected.php this session is not set.

like image 337
Wizard Avatar asked Mar 03 '26 18:03

Wizard


2 Answers

Don't use session_register(). It was removed in PHP 5.4.0. In index.php, add session_start(); to the top and replace your register call with $_SESSION['login'] = 'val';

like image 140
Lusitanian Avatar answered Mar 06 '26 07:03

Lusitanian


session_register() is deprecated, read here for more information:

http://php.net/manual/en/function.session-register.php

like image 38
Amaerth Avatar answered Mar 06 '26 08:03

Amaerth