Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: elbeer - helmikuu 01, 2014, 06:44:55 AP

Otsikko: Subscriptions and Sessions
Kirjoitti: elbeer - helmikuu 01, 2014, 06:44:55 AP
There is a problem with the subscriptions in that multiple users can pay for one membership and login via various locations and multiple users can login at the same time with the same account.

Is there any mod or method to prevent this by storing the session data in a dababase and checking if the current session matches the last login and if it does not boot the user. This will hopefully only allow one user at one time to use the account.

I would also like to know if this data is stored on which accounts have multiple users logging in as they are basically stealing the subscription fees
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: Storman™ - helmikuu 01, 2014, 08:05:24 AP
You need to provide more specific information with examples to make your question clearer. It's a little vague at the moment  ;)
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: elbeer - helmikuu 01, 2014, 08:07:09 AP
I have a subscripition forum where people pay to get access.

I want to prevent USER-A from sharing his login details with USER-B and stop them both from logging in at the same time.
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: Kindred - helmikuu 01, 2014, 08:54:01 AP
I don't believe that there is any feature or mod in SMF that would prevent that.

I mean, I log in from 8 different machines over the course of a day... by your thought, I wouldn't be allowed to log into my own account except from my primary machine.
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: elbeer - helmikuu 01, 2014, 08:56:21 AP
You can log in from multiple machines - what i am trying to prevent is 2 different people logging in at the same time.

However, I have managed to do it. thanks for you help guys
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: elbeer - helmikuu 01, 2014, 11:01:08 AP
Ok this is where I am at.

I have added an extra field to the user table to store a session variable. Which gets the variable from when the user logs in a session variable is passed to the field in the database.

Now what I want to do is check if session() matches what is stored in the database (session_logged)

I can get this working in a standalone script:

global $sourcedir;

if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
db_fatal_error();

global $smcFunc, $user_info;

$request = $smcFunc['db_query']('', '
  SELECT session_logged
  FROM {db_prefix}members
  WHERE id_member = '.$user_info['id'].'
  ');
if ($smcFunc['db_num_rows']($request) != 0)
{
  list ($result) = $smcFunc['db_fetch_row']($request);
}
else
  $result = false;
$smcFunc['db_free_result']($request);


$sesh= session_id();


if ($sesh != $result ){
echo "Wrong user";

$txt=$user_info['id']." is not the right user";
mail("[email protected]","User notice",$txt);

}


I have this in a separate file - now what I want to do is to add this to the forum for logged in users to check if the session matches if it does not match it will email me a notice that the user is not the correct user.

The part I am stuck with is can I add this as an include somewhere or do I have to hard code it and where would I do that.

I would also like to log out the user and redirect them to the login page
Otsikko: Re: Subscriptions and Sessions
Kirjoitti: elbeer - helmikuu 02, 2014, 05:10:56 AP
Maybe a better way to do this is to create it as a function and then do a check on logged in users.

I just need to know which files to put the function in, and where I can call the function for logged in users.