6

out of the blue I was getting the following error when logging in to one of my sites:

Call to undefined function session_register()

After some research I saw that session_register() is deprecated after PHP 5.4. I checked in my hosting control panel, and sure enough it says current version I'm running is PHP 5.4.19. I assume they just forced an upgrade which is why this problem seemed to occur out of the blue.

I looked through several Stack Overflow posts and reviewed links to PHP documentation. From what I gather, session_register() is deprecated and should be replaced with $_SESSION instead.

Problem is, both of those already appear in my code. Here is the code in my index.php file:

  53 <? if ($username) {
  54    session_register("ADMIN");
  55    $_SESSION['ADMIN'] = $username;
  56 ?>

So I hoped just by removing line 54 (the deprecated piece) then it should work, however that is not the case. It broke the code when I did that.

Based on other posts I read HERE and HERE they seem to be saying that the code I see in line 55 above should by itself do the trick. So I'm a bit confused why it didn't work. If anyone can tell me what code I should use I would sincerely appreciate it. The developer of the script is not really offering support.

NOTE: Also, yes there is session_start() called at the very top of the page.

Community
  • 1
  • 1
Michael Curving
  • 71
  • 1
  • 1
  • 4
  • Do you have a `session_start()` on your page? – gen_Eric Sep 17 '13 at 21:00
  • which error do you get for `$_SESSION['ADMIN']`? – 01e Sep 17 '13 at 21:05
  • yes, there is a session_start() at the top of the page – Michael Curving Sep 17 '13 at 21:10
  • How did the code "break"? – gen_Eric Sep 17 '13 at 21:11
  • possible duplicate of [How to fix the session\_register() DEPRECATED problem?](http://stackoverflow.com/questions/3682615/how-to-fix-the-session-register-deprecated-problem) – dev-null-dweller Sep 17 '13 at 21:35
  • @RocketHazmat, this is the error that comes up after I remove line 54: Fatal error: require(): Failed opening required './wp-blog-header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') on line 17. There is nothing in line 17 though except for a closing bracket. – Michael Curving Sep 17 '13 at 21:40
  • @dev-null-dweller note that I referenced that thread above. It may be a duplicate but the other thread didn't help me address the problem I'm having, so either my case is different somehow, or else more clarification is needed. thanks – Michael Curving Sep 17 '13 at 21:43
  • 1
    @MichaelCurving: I highly doubt the 2 errors are related. You've "fixed" the `session_register` error, now you've discovered another one. `Call to undefined function` is a "fatal error", which will stop PHP. Now that it can get past that section, it found another fatal error. – gen_Eric Sep 17 '13 at 21:44
  • 1
    @RocketHazmat there must be a ghost in the machine. I decided to delete the entire directory and then uploaded all the files clean again. Then I made the change removing line 54 and replaced just the index.php file. Now when I login, I'm not getting the 2nd error I referred to on line 17. Instead I'm still getting the exact same error as the 1st time, citing line 54, which is now '$_SESSION['ADMIN'] = $username;' – Michael Curving Sep 17 '13 at 22:25

4 Answers4

5

Possible it is missing the call for session_start, session_register make this automatically, so what you have to do is just make sure that you have called session_start before use $_SESSION global.

You can check more here http://www.php.net/manual/en/function.session-register.php

If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.

gen_Eric
  • 214,658
  • 40
  • 293
  • 332
krolow
  • 191
  • 2
  • 6
2

Because session_register('ADMIN') registers the global variable with that name in the current session, so maybe in your code you have $ADMIN variable, find them and replace them with:

$_SESSION['ADMIN']

I hope this will help you.

01e
  • 713
  • 3
  • 14
1

Looks like I overlooked the obvious. I was on the right track by simply removing the old session_register code.

But notice the original code I posted starts

<?

instead of

<?php

doh

Michael Curving
  • 71
  • 1
  • 1
  • 4
0

Add a session_start() at the begining of your code and $_SESSION to manipulate it or create it.

Starx
  • 75,098
  • 44
  • 181
  • 258