*

KaloSex

  • ****
  • 135 posts
trying to make an external plugin work with no luck.
« on: May 30, 2023, 03:28:48 PM »
Hello, i am trying to make an external plugin to work / pull user id:
I got these two generic codes but anything i tried by altering them didn't work

Code: [Select]
  function get_user_id()
{
    global $db;
    $userid = NULL;
    if (!empty($_COOKIE['hash']))
    {       
        $result = $db->execute("
            SELECT user_id
            FROM " . TABLE_PREFIX . "session
            WHERE hash = '" . $db->escape_string($_COOKIE['hash']) . "'
        ");
        if ($row = $db->fetch_array($result))
        {
            $userid = $row['user_id'];
        }
    }
    return $userid;
}

or:

Code: [Select]
function get_user_id()
    {
        $userid = NULL;
       
        if (isset($_COOKIE['userid']))
        {
            $userid = $_COOKIE['userid'];
        }

        return $userid;
    }

any idea anyone?

*

MB Themes

Re: trying to make an external plugin work with no luck.
« Reply #1 on: May 30, 2023, 03:37:35 PM »
Not clear what you want.
2nd function just get user id from cookies if exists
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

KaloSex

  • ****
  • 135 posts
Re: trying to make an external plugin work with no luck.
« Reply #2 on: May 30, 2023, 03:52:51 PM »
The code is used for the plugin to be able to pull the user details from osclass logged it user, so it gives it the username.

Both of those two doesn't work and it's provided from the plugin but not speficaly for osclass, so i need to alter them to work.

Both codes try to pull the username and i can use any of the two works better once altered

*

MB Themes

Re: trying to make an external plugin work with no luck.
« Reply #3 on: May 30, 2023, 07:12:11 PM »
Thats wrong code .
Use osc_logged_user() function
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

KaloSex

  • ****
  • 135 posts
Re: trying to make an external plugin work with no luck.
« Reply #4 on: May 30, 2023, 10:34:02 PM »
i cant use this function on the external script.. I need to pull the user id from session or cookie

So i tried this with no luck:

function get_user_id()
{
    $userid = NULL;
    if (!empty($_COOKIE['oc_user_session']))
    {
        $session = Session::newInstance()->findBy('s_secret', $_COOKIE['oc_user_session']);
        if ($session)
        {
            $userid = $session['s_userid'];
        }
    }
    return $userid;
}

*

MB Themes

Re: trying to make an external plugin work with no luck.
« Reply #5 on: June 01, 2023, 03:06:06 PM »
:)
Does not work that way, sorry...
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

KaloSex

  • ****
  • 135 posts
Re: trying to make an external plugin work with no luck.
« Reply #6 on: June 01, 2023, 03:31:11 PM »
i solved it, thank you. You can close the thread

*

Hugo

  • ****
  • 182 posts
Re: trying to make an external plugin work with no luck.
« Reply #7 on: June 01, 2023, 07:08:59 PM »
:)
Does not work that way, sorry...

From maybe everyone on the community; As customer support out here on the forum it would be good to provide an answer instead of a statement that the above is false...


*

MB Themes

Re: trying to make an external plugin work with no luck.
« Reply #8 on: June 01, 2023, 07:35:43 PM »
Attempt was to get osclass data from session, by external application.
That is wrong and should never work like that.
So there is nothing to doscuss about it, you should have provider code in osclass where you can request data (like rss or rest api or whatever else).
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

KaloSex

  • ****
  • 135 posts
Re: trying to make an external plugin work with no luck.
« Reply #9 on: June 01, 2023, 08:30:57 PM »
there were two codes, one with session, one with cookie. Since none helped me to pull the user id from the cookie that osclass creates, i just created another cookie myself and i extracted the user id from this cookie and things worked out. No rss or api. So it's done with 4-5 lines of code - if anyone needs it