Page 1 of 1

session_register fatal error.

PostPosted: 21. November 2012 19:17
by evolvelab
Hi guys, new here.

This is the first time i have ever come accross this error, maybe because it's been a while since i upgraded...

session_register basically doesn't exist anymore...

this is the code i was using before...

Code: Select all
session_register('username');
$_SESSION['username'] = $inf->username;   


I basically want that, but a fully functioning version, can anybody help me?

Thanks
Kind Regards
Jake Duncan

Re: session_register fatal error.

PostPosted: 21. November 2012 19:40
by WilliL
Hi Jake,

session_register() is depredecate since PHP 5.3.0.
I would mark out this line. If I read http://php.net/manual/en/function.session-register.php right, your excample shows 2 times the same work. once in current forme and one in elder form.

If you would like to keep this line, I fear you have to use an elder verion of XAMPP

Re: session_register fatal error.

PostPosted: 21. November 2012 19:45
by evolvelab
Hi Willi,

I have just seen

Code: Select all
<?php
// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";

// The old way was to use $HTTP_SESSION_VARS
$HTTP_SESSION_VARS["spongebob"] = "He's got square pants.";
?>


from the link you added...

i have changed the line to

Code: Select all
$_SESSION["username"] = "$inf->username";


But a session still doesn't start...
It has boggled my brain, i know it must be something so simple.

Regards
Jake

Re: session_register fatal error.

PostPosted: 21. November 2012 20:05
by evolvelab
Ok, so i have fixed the problem,

had to make some minor changes in the script for it to work properly, but i figured it out!

Thanks!

For future reference, if anyone else stumbles accross this problem.. thats an IF.. because it's only me that stuff like this happens to lol

the fix is..

Code: Select all
session_start();


must obviously start at the beginning or before the following code,

You can use this, if you just wish to register the username as a session

Code: Select all
$_SESSION["username"] = "$variableforyourusername";


and it should work. :) Peace

Re: session_register fatal error.

PostPosted: 21. November 2012 21:13
by WilliL
http://php.net/manual/en/function.session-register.php
Code: Select all
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.


For i started php programming later I didn't knew that in earlier version you mustn't use "session_start();" ;)