Session Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Session Error

Post 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.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Session Error

Post 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>";
?>
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Re: Session Error

Post by nitediver »

What happened with "session_register"?
If work, so can I use that to carry the variable to another page?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Session Error

Post 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 :)
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Re: Session Error

Post by nitediver »

Ok, thanks for the explaination.
Post Reply