Checking for login cookie

Started by tater pie, March 29, 2019, 04:47:41 PM

Previous topic - Next topic

tater pie

Theres definitely gotta be a post about this somewhere but i cant find it! :(

I'm making a "top list" part of my website and it is unrelated to SMF

But i have SMF forums and i wanna check the login of users in that site from the forums login cookie

how can i access said cookie in php if it exists, and get the username(not password) from that cookie so that i can display a button if it exists? i know how all the php code will work except for the part about grabbing the cookie i assume it would be something like this


$cookie = $_COOKIE["smflogin"];
if (isset($cookie)) {
     if($cookie['username'] == $username) {
          ?> <button class="editbutton" onclick="location.href='edit.php'">Edit</button><?php
     
}
}


If that code would work then really all i need is the name of the cookie and maybe how to grab the value of the username from that cookie



Arantor

Better still... include the SSI.php file and boom, it should work it out for you and give you access to details about the user without you having to do any work.

tater pie

Quote from: Arantor on March 29, 2019, 04:48:45 PM
Better still... include the SSI.php file and boom, it should work it out for you and give you access to details about the user without you having to do any work.

Its that simple? like should i just go look in SSI and see what the fields are called?

Arantor

No, you just include the file and then examine $user_info for all those sweet sweet details.

Getting the data out of the database is otherwise really complicated since not even the cookie name is actually consistent between installations and the cookie won't contain the username anyway so you have to go make a roundtrip to the database.

tater pie

Quote from: Arantor on March 29, 2019, 04:53:53 PM
No, you just include the file and then examine $user_info for all those sweet sweet details.

Getting the data out of the database is otherwise really complicated since not even the cookie name is actually consistent between installations and the cookie won't contain the username anyway so you have to go make a roundtrip to the database.

rofl so


$user_info['username'];

???
that is almost too simple  ;D

Thank you very much this is exactly what i needed within seconds


Arantor

You might not want username; users can change their display name in a default installation so you might want real_name (or possibly member_name, I forget which) instead.

tater pie

Quote from: Arantor on March 29, 2019, 05:07:00 PM
You might not want username; users can change their display name in a default installation so you might want real_name (or possibly member_name, I forget which) instead.

Isn't there a checkbox to disallow users to change their display names? because i believe i checked that box as i only want to offer that feature to administrators 

i may be mistaken though

and in which case the user would request a name change the admin would change his name manually  in the users account settings, that would change the real_name/member_name right?

Doug Heffernan

Only the real_name field will change to hold the new username after the change. Whereas the member_name field will still contain the original name of the user.

Arantor

member_name will hold the username which is what they login with; real_name is what they display as - e.g. I don't type in 'Arantor' to log in.

Advertisement: