Solved

Fatal error: Call to undefined function session_is_registered() in

Posted on 2014-10-03
6
183 Views
Last Modified: 2014-10-16
Hi,

I know the cause of this issue. I have PHP 5.4 on a new host and this error is due to that since it was older on another host.

Is there something I can edit in a custom php.ini file to make this go away and still keep using it?

Thanks!
0
Comment
Question by:Computer Guy
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40359831
You can't use it, it's been removed.

Now you have to check if it is set

if(isset($_SESSION['session_name'])){
...
0
 
LVL 9

Accepted Solution

by:
Brian Tao earned 500 total points
ID: 40359924
I haven't tried it but I think you can add the following code to your script so that it runs on both old and new PHP versions:
if (!function_exists('session_is_registered')){
  function session_is_registered($sess_name){
    return (isset($_SESSION[$sess_name]));
  }
}

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40360143
Please see the second foreword to this article:
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

Executive summary: This was deprecated at PHP 5.3, over 5 years ago.  There are other, current PHP functions that do things the right way, so just correct the code.  Here's one suggestion:
http://php.net/manual/en/function.session-is-registered.php#111878
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Author Comment

by:Computer Guy
ID: 40360815
This is what the original code is:
      if (session_is_registered($k))        continue;

Is this the correct syntax to replace it with?
      if (!function_exists('session_is_registered($k'))continue;{
  function session_is_registered($k){
    return (isset($_SESSION[$k]));
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40360825
Umm, probably this is a correct replacement.
if (isset($_SESSION[$k])) continue;

Open in new window

If you want to explore the deep-background thinking on the session-register concept and why it's not used any more, learn about register-globals.  Automatic injection of external variables was supposed to make PHP "easy" but it actually made PHP horribly insecure and hackable, so we don't do that any more.

If you look at your code base and find a lot of instances of session_is_registered() then it might make sense to define the function, but my thinking would be to just correct the code, since the correction using isset() will be forward and backward compatible.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40384120
To amyone coming upon this Q/A in the future, the explanation of the issue can be found here:
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28530812.html#a40360143

And the correct answer (at least the one that won't get you fired) is here:
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28530812.html#a40360825
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question