May 9, 200917 yr I know the function, but I'll be damned if I know how to use it properly, lol. I'm making a script to check if a user is logged in, and there is one bump in the road I can't resolve: how to check if an IPB session is valid. Here's what I have so far: // User ID $user_id = isset($_COOKIE['member_id']) ? $_COOKIE['member_id'] : ""; // Check if logged in $cook_session = $_COOKIE['session_id']; $cook_hash = $_COOKIE['pass_hash']; if (!empty($cook_session) && !empty($cook_hash)){ if ($cook_session != "0" && $cook_hash != "0"){ $ipb_session = mysql_result(mysql_query(sprintf("SELECT id FROM ". $ipb_prefix ."_sessions WHERE member_id='%s'", mysql_real_escape_string($user_id))),0); $ipb_hash = mysql_result(mysql_query(sprintf("SELECT member_login_key FROM ". $ipb_prefix ."_members WHERE id='%s'", mysql_real_escape_string($user_id))),0); if ($cook_session = $ipb_session && $cook_hash = $ipb_hash){ if (session_is_registered(/* what to put here? */)){ $logged_in = true; } else { $logged_in = false; } } else { $logged_in = false; } } else { $logged_in = false; } } else { $logged_in = false; } The rest of the script works fine, there are some kinks, but the main functionality is good. It's just that, when you log into an IPB forum, a session is created. Now if you are inactive on the forum for a certain amount of time, the session is destroyed and you are logged out. The problem with my script is that it doesn't know when the session is destroyed therefore it still thinks you're logged in when you aren't.
June 5, 200917 yr I'm not strictly sure on how to solve your problem as I don't know about IPB's session policies. I will however mention that the PHP function "session_is_registered" is deprecated as of PHP 5.3.0. This means that in the even of your server upgrading, your script will cease to work. The developers of PHP usually deprecate functions in favour of better methods. It seems in this case that you should use "isset" along with a session variable to see if it's been set. For example "isset($_SESSION['logged_in']). More information on this change can be found at http://uk3.php.net/session_is_registered. Dan
Create an account or sign in to comment