Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Check if IPB session is valid?

Featured Replies

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. ;)

  • 3 weeks later...

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.