Page 1 of 1

session_register depricated

Posted: Wed Apr 11, 2012 11:32 pm
by inosent1
i have been using session_register to pass along the username to the various pages of my data system. i remember it took me forever to figure out how to do that. i like it because as i go from page to page while logged in i can use a query based on the username and do useful things with it

in php 5.3+ i get the 'deprecated' error messages which are annoying. so what i am looking for is a way to register the username variable just like i did with session_register

the login page:

Code: Select all

$username = count($_POST)?$_POST['username']:'';
session_register("username");
$_SESSION['user']=$username;

then all the following pages

Code: Select all

 session_start();
// to see if the user is logged in
if(!session_is_registered(username)){
header("location:login.php");
}


$usera = $_SESSION["user"];
//echo 'here ' . $usera;
 
so i need a way to do what session_register used to do, as easily as it did.

Re: session_register depricated

Posted: Wed Apr 11, 2012 11:57 pm
by requinix
What you actually need is to not use session_register() and session_is_registered(). Those deprecation warnings aren't there to make your life harder: they're there to tell you what not to do.

Use $_SESSION. To "register" a variable just stick it in the array, like you're doing now, and to check if one "is registered" use isset with the array.

Re: session_register depricated

Posted: Thu Apr 12, 2012 9:20 am
by inosent1
thanks. it was easier than i thought

login

Code: Select all

$username = count($_POST)?$_POST['username']:'';
$Session = $_SESSION["Session"];
$_SESSION['user']=$username;		


subsequent pages

Code: Select all

<? session_start();
if(!$_SESSION["user"]){
header("location:login.php");

?>