kporter.porter Posted October 19, 2007 Share Posted October 19, 2007 Still trying to update this website from like 2000. It looks like my sessions are not working correctly. I get fatal errors on line 3 in this code: <table cellspacing=0 cellpadding=3 border=0 width=70%> <tr><td align=center><h3>Welcome, <u><b><?php= GetSessionVar("full_name") ?></b> </td> </tr> </table> Call to undefined function GetSessionVar(). This is the error I get in my IDE. The webpage just shows "Welcome _". Combine this with the fact that I get an undefined index error for this code: function _SessionCreate($SessionName) { $Db=new sql; global $_SESSION_DATA; $GLOBALS["$SessionName"]=md5 (microtime() . $_SERVER['REMOTE_ADDR']); $Db->exec("insert into session (sid) values ('" . $GLOBALS["$SessionName"] . "')"); $_SESSION_DATA["$SessionName"]=array(); SetCookie ("$SessionName", $GLOBALS["$SessionName"],0,"/"); return; } The problem is with "$_SERVER['REMOTE_ADDR']);". The REMOTE_ADDR being the problem. Some of the pages using the session stuff worked before i upgraded to 5.2.4. I am thinking all the code worked in 2000 but now is outdated after the upgrade. If this is the case what verbs should I be using? I have read where I can use isset to check the variable, but not sure how to write that around this multiple coded line. Oh and what does the "space . space" do? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/ Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 In PHP 5, to set a session, you would do this $_SESSION['name'] = "blah"; Then to echo it out, you would just do this echo $_SESSION['name']; So your definitely using some old methods. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373408 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 Figured as much. Are the Set ang Get verbs still usable? What code would I replace with the code you wrote? Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373419 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 <table cellspacing=0 cellpadding=3 border=0 width=70%> <tr><td align=center><h3>Welcome, <u><b><?php= $_SESSION['full_name'] ?></b> </td> </tr> </table> This part is just a guess. <?php function _SessionCreate($SessionName) { $Db=new sql; global $_SESSION_DATA; $_SESSION["$SessionName"]=md5 (microtime() . $_SERVER['REMOTE_ADDR']); $Db->exec("insert into session (sid) values ('" . $_SESSION["$SessionName"] . "')"); $_SESSION_DATA["$SessionName"]=array(); SetCookie ("$SessionName", $_SESSION["$SessionName"],0,"/"); return; } ?> I'm not really sure where your getting this from $_SESSION_DATA So I can't really help you with that one Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373424 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 Thanks for the info. I have a bad feeling that my sessions aren't working at all. It allows me to login, but is then supposed to welcome the person by name. It isn't doing that. I'll keeping searching. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373434 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 When they log in, register the session the way I showed you. Are you doing it the old way? Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373436 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 I changed my code. Now I get "Fatal Database Error. ERROR: duplicate key violates unique constraint "session_pkey"" Not good. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373465 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 Do you have a field in one of your tables called "session_pkey" that is a primary key? Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373470 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 Yes I just found it. It has 2 entries in the database. The one that coincides with my latest login doesn't have the SID listed. I must not be passing the SID to the DB. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373477 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 Now I am not getting the error. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373479 Share on other sites More sharing options...
kporter.porter Posted October 19, 2007 Author Share Posted October 19, 2007 Changed the first code from my first post to: <table cellspacing=0 cellpadding=3 border=0 width=70%> <tr><td align=center><h3>Welcome, <u><b><?php $name = GetSessionVar("full_name"); print "$name" ?></b> </td> </tr> </table> Now it works and say's Welcome (the persons name). Now on to the next problem. I'll be back I am sure thanks for the help poco, I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/73980-setsessionvar-getsessionvar/#findComment-373494 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.