This topic is locked
[SOLVED]

 use $_session["userid"] in custom button

12/3/2019 3:50:51 PM
PHPRunner General questions
C
CTom author

Hi all,
I am trying to make a button which inserts some data into a table, including the user id number.
The server event insert goes fine but without the userid value declared as
$id = $_SESSION["userid"]

.
Not really sure how to proceed, any help or advice highly appreciated.
Thank you.
Catalin

Sergey Kornilov admin 12/3/2019

In PHP most things are case sensitive. If you are trying to use a built-in session variable $_SESSION["userid"] is incorrect while $_SESSION["UserID"] is correct.

C
CTom author 12/4/2019



In PHP most things are case sensitive. If you are trying to use a built-in session variable $_SESSION["userid"] is incorrect while $_SESSION["UserID"] is correct.


Thank you for the reply. There is no case sensitive issue here, I am definitely missing something here and the documentation on tri part events is scarce.
I have declared the variable in after successful login but it is not used in the server event. I will continue digging, perhaps I can find a piece of useful info somewhere.
Catalin

N
Nir Frumer 12/4/2019

hi

$_SESSION['userid'] stores the user's name
in after successful login event, add

$_SESSION['nUserId']=$data['id'] (or whatever your id field name is)
then use $_SESSION['nUserId'] in your button
hope it helps,

Nir.

Sergey Kornilov admin 12/4/2019

Documentation is always the first to blame.
The problem is that you are trying to use $_SESSION["userid"] that conflicts with the system session variable $_SESSION["UserID"]. As Nir suggested - use another session variable name.
Better yet, if you are trying to use ID of the user from the login table, there is a recommended API for that:

https://xlinesoft.com/phprunner/docs/secapi_current_user_data.htm

C
CTom author 12/5/2019

Hi,
Will try your suggestions and update this topic with results.
Thank you very much for your advices.
Catalin

C
CTom author 12/17/2019

It works with $_SESSION['userid']
It does not work with $_SESSION["userid"] (documentation here: https://xlinesoft.com/phprunner/docs/save_user_data_in_session_variables.htm)
Catalin