-3

How can I for the best change this PHP code:

<?php
session_register("loginusername"); 
?>

and

<?php session_start(); 
$loginusername = $_SESSION['username']; 
$loginpassword = $_SESSION['password']; 
if(!session_is_registered(loginusername)) { 
header("location:fanion.php"); 
}
 ?>

to become no errors in PHP 5.6.

NikiC
  • 98,796
  • 35
  • 186
  • 223
LUC TERMOTE
  • 31
  • 1
  • 8

2 Answers2

1

change ...
session_register("loginusername");
... to ...
$_SESSION['loginusername'] = $username;

... and change ...
if(!session_is_registered(loginusername))
... to ...
if (empty($_SESSION['loginusername']))

neokio
  • 5,143
  • 36
  • 57
  • Thanks, but is there a difference between empty() and !isset()? – LUC TERMOTE Feb 06 '15 at 16:34
  • definitely .. http://stackoverflow.com/a/7191642/864908 ... but in this case, i think an empty username should be the same as it not being set :) – neokio Feb 06 '15 at 16:38
0

session_registered()

method is deprecated instated of you can use Global variable

 $_SESSION["USER_SESSION_NAME"]=session value;

you can check session is started or not by using

empty ( ) / isset ( )

method

if(isset($_SESSION[""USER_SESSION_NAME"]))
{
           //YOUR CODE
}