Check if user logged in with SID?

Discussion forum for MOD Writers regarding MOD Development.
Locked
AwesomeStyle
Registered User
Posts: 64
Joined: Tue Jul 16, 2013 7:10 pm

Check if user logged in with SID?

Post by AwesomeStyle »

How can I check only with SID if an user is logged in?

Thanks!
I will install MODs for your forum as cheap as 5-15$ in BitCoin depending on the MOD install level & time. Contact via PM.

User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Check if user logged in with SID?

Post by DionDesigns »

If this is inside phpBB, there is no need for any checking since phpBB supplies the $user object. If this is for an external page which includes the phpBB common.php file, again, the $user object will be available.

If this is for an external page which includes no phpBB code, how are you obtaining the SID? If through a query string, you'll need to query the _sessions table. If through a cookie, you should also check the _k cookie, and if it exists, query the _sessions_keys table.

AwesomeStyle
Registered User
Posts: 64
Joined: Tue Jul 16, 2013 7:10 pm

Re: Check if user logged in with SID?

Post by AwesomeStyle »

DionDesigns wrote:If this is inside phpBB, there is no need for any checking since phpBB supplies the $user object. If this is for an external page which includes the phpBB common.php file, again, the $user object will be available.

If this is for an external page which includes no phpBB code, how are you obtaining the SID? If through a query string, you'll need to query the _sessions table. If through a cookie, you should also check the _k cookie, and if it exists, query the _sessions_keys table.
Code sends a query to PHP check_session.php (example):

Code: Select all

www.site.com/check_session.php?=f79cf85303b2fd42163ad161e5d0f7c4
So what I need is to return session_user_id of that SID.
I will install MODs for your forum as cheap as 5-15$ in BitCoin depending on the MOD install level & time. Contact via PM.

AwesomeStyle
Registered User
Posts: 64
Joined: Tue Jul 16, 2013 7:10 pm

Re: Check if user logged in with SID?

Post by AwesomeStyle »

If it was able to find session_user_id then the script will echo this:

Code: Select all

1 session_user_id
. (number 1, then space, then session_user_id)

If it was not able to find it or

Code: Select all

if (isset($_GET['sid']) == false)
then

Code: Select all

echo "0";
I will install MODs for your forum as cheap as 5-15$ in BitCoin depending on the MOD install level & time. Contact via PM.

User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Check if user logged in with SID?

Post by DionDesigns »

If this is being done client-side via AJAX or form submission, you don't need session IDs. Your check_session.php file could create a phpBB session and return the information in whatever format you desire.

However, if all you want to do is return a user ID based on a session ID, a query set up like the following would work:

Code: Select all

$sessid = (session ID);
$sql = 'SELECT u.username, u.user_type, s.session_user_id
	FROM phpbb_sessions s, phpbb_users u
	WHERE s.session_user_id = u.user_id
	AND s.session_id = ' . $sessid;
This returns more data than you requested. Since bots have unique user IDs, you also need the user_type information to determine whether the user ID returned belongs to a bot. I added the username because it seemed like a good idea to have that information as well. 8-)

AwesomeStyle
Registered User
Posts: 64
Joined: Tue Jul 16, 2013 7:10 pm

Re: Check if user logged in with SID?

Post by AwesomeStyle »

Nevermind, I got it working.
I will install MODs for your forum as cheap as 5-15$ in BitCoin depending on the MOD install level & time. Contact via PM.

User avatar
Steve
Registered User
Posts: 1078
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: Check if user logged in with SID?

Post by Steve »

its as simple as $user->session_id

alexander7566
Registered User
Posts: 171
Joined: Mon Mar 12, 2012 5:26 pm

Re: Check if user logged in with SID?

Post by alexander7566 »

Was you doing this via a file_get_contents or something similar from another domain? I have been trying to get something like this for weeks. Could you share how you got the session id on another domain?


AwesomeStyle
Registered User
Posts: 64
Joined: Tue Jul 16, 2013 7:10 pm

Re: Check if user logged in with SID?

Post by AwesomeStyle »

alexander7566 wrote:Was you doing this via a file_get_contents or something similar from another domain? I have been trying to get something like this for weeks. Could you share how you got the session id on another domain?
I am doing it via same web server but from another domain. Just include the phpBB files and use $_GET.
I will install MODs for your forum as cheap as 5-15$ in BitCoin depending on the MOD install level & time. Contact via PM.

Locked

Return to “[3.0.x] MOD Writers Discussion”