Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP alternative to session_is_registered

Tags:

php

session

does anyone knows the alternative to the deprecated function session_is_registered in PHP5?

here's my code:

ob_start();

session_start();

if(!session_is_registered(myusername))

{

    header("location:main_login.php");

}

ob_flush();

Thanks,

Mauro

like image 648
Mauro74 Avatar asked Apr 08 '10 14:04

Mauro74


3 Answers

"You need to set and reference $_SESSION variables only." For example:

if( isset($_SESSION[$myusername]) )

From http://www.phpfreaks.com/forums/index.php?topic=263189.0

like image 57
zaf Avatar answered Oct 14 '22 02:10

zaf


on a side note, best use $_SESSION['username'] = $myusername;. Using the $_SESSION[$myusername] as a variable may overwrite existing variables in the session.

like image 23
Sirber Avatar answered Oct 14 '22 03:10

Sirber


But if you set anything in the session variable it will display you the protected page: e.g.,

<?php
    session_start();
    if(isset($_SESSION[$myusername])){
        echo "welcome to protected page.";
    }
    else {  
        header('location:login.php');
        die;     
    }
 ?>
like image 20
kapil Avatar answered Oct 14 '22 02:10

kapil