Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change of PHP Version has caught me out.

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
1&1 Hosting have recently pressed me to update the version of php that is used on my hosting package (now using 5.5). Unfortunately there have been some repercussions!
The latest is that people cannot log in to a site. They get the error "Fatal error: Call to undefined function session_register() in /homepages/35/d406485504/htdocs/hopeless/writers2/edit/login.php on line 36"
The Head of the webpage concerned was written with the help of DW2004MX, and no doubt that is the problem. I have attached it.
I wonder if anyone can help me change the code so that users can again login.
Thanks for looking.
 
 http://files.engineering.com/getfile.aspx?folder=1fe54afa-52bc-4f06-a247-b65e3c444dd3&file=login_prob.rtf
best solution is to recode.

alternatively work around it by adding this to a file that is called on every page

Code:
if(!function_exists('session_register')):
 function session_register($var){
    if(session_id() == '') session_start();
    if(is_array($var)):
      foreach($var as $v=>$val) $_SESSION[$v] = $val;
    else:
      $_SESSION[$var] = '';
    endif;
 }
endif;
 
I agree with jpadie. Recode the parts that use session_register would be the best choice.

The recreation of the session_register function would also work, but seems a little kludgy to include a file to add a function to replace a deprecated one. When using $_SESSION is far far easier and quicker.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks for the advice. I will need a bit more "hand-holding with this I'm afraid, as I have tended to rely on Dreamweaver to do the coding for me.
I have substituted
$_SESSION["MM_Username"]; for session_register("MM_Username"); and
$_SESSION["MM_UserGroup"]; for session_register("MM_UserGroup");

but I realise that there must be more to it than that because although I am not getting an error message anymore, I am not being granted access to the next webpage, simply passed to the login_retry.php page, (where I have made the same change as above to the code)
I'd be grateful if you could explain how I get it to accept the username/password.
 
yes. first you must enable the session

Code:
if(session_id() == '') session_start();

then you can treat the session superglobal like any array

Code:
$_SESSION["MM_Username"] = 'jpadie';

just putting
Code:
$_SESSION['MM_Username'];
will throw an error. you must set it to something (even if only a NULL value).
 
You need to set the session variable to something. Not just instantiate it. So:

Code:
$_SESSION["MM_Username"][red][b] = $loginUsername;[/b][/red];
$_SESSION['MM_UserGroup'][red][b] = $loginStrGroup[/b][/red];

You can skip the globals assignment and assign the values directly to the session vars.

Also you may also need to change how your login validation script checks for the existence of those session variables.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Vacunita, your code addition works first time without any further adjustment, as far as I can see. Magic!
(Is that right, the 2 semi-colons in the first line of code? No doubt it is, as it works fine.)
Many thanks.
 
No sorry, that was a typo. Only one semicolon is needed to end a line in PHP. More semicolons after that are meaningless to PHP so they don't generate errors.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top