Page 1 of 1

Session Error

Posted: Tue Apr 27, 2010 7:55 am
by nitediver
This warning message only appear for the first time the code run.
I also have another code for login system but never received this error message before.
What could possibly wrong?

[text]
Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
[/text]

Code: Select all

<?
session_start();
$a = "this is a";
$b = "this is b";

session_register("a");
session_register("b");

echo $_SESSION['a']."<br>".$_SESSION['b'];

echo "<br>";
echo "<a href=\"2.php\">Next</a>";
?>
Thanks.

Re: Session Error

Posted: Tue Apr 27, 2010 8:13 am
by Apollo
Do not use session_register. simply do this instead:

Code: Select all

<?php
session_start();
$_SESSION['a'] = "this is a";
$_SESSION['b'] = "this is b";

echo $_SESSION['a']."<br>".$_SESSION['b']."<br><a href='2.php'>Next</a>";
?>

Re: Session Error

Posted: Tue Apr 27, 2010 8:49 am
by nitediver
What happened with "session_register"?
If work, so can I use that to carry the variable to another page?

Re: Session Error

Posted: Tue Apr 27, 2010 8:59 am
by Apollo
You simply don't need session_register. The $_SESSION array contains all session variables, whatever you put in there is automatically carried to subsequent pages (as long as you call session_start at the beginning).

session_register was an awkward method of binding global variables to session variables. Deprecated and not necessary (as $_SESSION alone works just fine), so don't use it :)

Re: Session Error

Posted: Tue Apr 27, 2010 9:04 am
by nitediver
Ok, thanks for the explaination.