Jump to content

Error: Deprecated: Function session_is_registered() is deprecated in


NiallFH

Recommended Posts

I wondered if anyone could offer me some advice on how to solve this problem:

 

I am using MySQL 5.0 and PHP 5

 

and getting the following error:

 

"Deprecated: Function session_is_registered() is deprecated in"

 

The code is at the very top of my php file and there is nothing being sent to the browser prior to this code.

 

<?


session_start();


include('admin/user.php');
$connection = mysql_connect("$host","$user","$password")
or die(mysql_error());
mysql_select_db("$txt_db_name",$connection)
or die(mysql_error());


$scriptname = "matches.php?" . $_SERVER['QUERY_STRING'];
$pref = mysql_query("SELECT * FROM tplss_preferences WHERE ID = '0'",$connection) or die(mysql_error());
$pdata = mysql_fetch_array($pref);
mysql_free_result($pref);


if(!session_is_registered('defaultseasonid_tplss') || !session_is_registered('defaultmatchtypeid_tplss'))
{
$_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID'];
$_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID'];
$seasonid = $_SESSION['defaultseasonid_tplss'];
$compid = $_SESSION['defaultmatchtypeid_tplss'];
}
else
{
$seasonid = $_SESSION['defaultseasonid_tplss'];
$compid = $_SESSION['defaultmatchtypeid_tplss'];
}

?>

Link to comment
Share on other sites

First comment on this page will show you what you should do:

http://php.net/session_is_registered

 

Also, I recommend reading about the other session functions, and their replacements. Seems like you've been using a guide which is a "bit" out of date, either that or written by someone who didn't know what they were doing.

Link to comment
Share on other sites

I read something similar elsewhere, but I'm slightly confused re: syntax.

 

Is this close to correct?

 

if(isset('defaultseasonid_tplss') && isset('defaultmatchtypeid_tplss'))
{
$_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID'];
$_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID'];
$seasonid = $_SESSION['defaultseasonid_tplss'];
$compid = $_SESSION['defaultmatchtypeid_tplss'];
}
else
{
$seasonid = $_SESSION['defaultseasonid_tplss'];
$compid = $_SESSION['defaultmatchtypeid_tplss'];
}

Link to comment
Share on other sites

As you've fixed it, I thought I'd just post a cleaned up version of your previous code. So that you can see how easy it can be done. ;)

if (!isset ($_SESSION['defaultseasonid_tplss'])) {
   $_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID'];
}

if (!isset($_SESSION['defaultmatchtypeid_tplss'])) {
   $_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID'];
}

 

Then just use the values from the $_SESSION array directly, instead of the two variables you defined above. By doing the way I've done it above, it will check and set the values independently of each other. So that if one is set, but the other missing, the script will set the default value to the missing one without affecting the one that's already set.

Your previous script required that both were set, otherwise it would always set both to the default value. Not sure if that was your intention. If it was, then this should do the same:

if (!isset ($_SESSION['defaultseasonid_tplss']) || !isset($_SESSION['defaultmatchtypeid_tplss'])) {
   $_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID'];
   $_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID'];
}

Edited by Christian F.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.