NiallFH Posted January 10, 2013 Share Posted January 10, 2013 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']; } ?> Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 10, 2013 Share Posted January 10, 2013 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. Quote Link to comment Share on other sites More sharing options...
NiallFH Posted January 10, 2013 Author Share Posted January 10, 2013 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']; } Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 10, 2013 Share Posted January 10, 2013 erm...that depends on your deffinition of "close". Your using the session array in a non-depreciated way, but you are nopt using isset() properly, and you are over complicating your variable handling. Quote Link to comment Share on other sites More sharing options...
NiallFH Posted January 10, 2013 Author Share Posted January 10, 2013 Thank you. Have now resolved this issue! Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 10, 2013 Share Posted January 10, 2013 (edited) 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 January 10, 2013 by Christian F. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.