Advertisement:

Author Topic: Checking for login cookie  (Read 1238 times)

Offline tater pie

  • Newbie
  • *
  • Posts: 6
Checking for login cookie
« on: March 29, 2019, 04:47:41 PM »
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

Code: [Select]
$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



Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,216
    • StoryBB/StoryBB on GitHub
Re: Checking for login cookie
« Reply #1 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline tater pie

  • Newbie
  • *
  • Posts: 6
Re: Checking for login cookie
« Reply #2 on: March 29, 2019, 04:51:55 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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,216
    • StoryBB/StoryBB on GitHub
Re: Checking for login cookie
« Reply #3 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline tater pie

  • Newbie
  • *
  • Posts: 6
Re: Checking for login cookie
« Reply #4 on: March 29, 2019, 05:00:42 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

Code: [Select]
$user_info['username'];
???
that is almost too simple  ;D

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


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,216
    • StoryBB/StoryBB on GitHub
Re: Checking for login cookie
« Reply #5 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline tater pie

  • Newbie
  • *
  • Posts: 6
Re: Checking for login cookie
« Reply #6 on: March 29, 2019, 05:37:40 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?

Offline doug_ips

  • Jr. Member
  • **
  • Posts: 298
Re: Checking for login cookie
« Reply #7 on: March 29, 2019, 05:50:45 PM »
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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,216
    • StoryBB/StoryBB on GitHub
Re: Checking for login cookie
« Reply #8 on: March 29, 2019, 05:55:42 PM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.