Jacky Ho
Jacky Ho

Reputation: 13

Is it possible to pass in the session as a variable like in Python for PHP?

So I've been working on porting a python tester to PHP, but I'm fairly new to PHP still. I understand there is a session command within PHP, and I've read the documentation as well as other questions that have come up here in stackoverflow that are close to it, but not quite what I'm looking for.

So my question is whether if there is something similar to sess = requests.Session() from python to PHP, i.e. is there something I could pass in just like I did in python that can occur also in PHP?

EDIT: So I've re-read the documentations for both the python Request package and Sessions for PHP. And I think the meat of my question is if there is a way to have a session object in PHP that holds persistent parameters across POST and GET Request? And to further explain, my main problem is that I have certain POST and GET endpoints that require a login, but even after using the login POST first, I still receive a 401 error code after.

Example Code: $current->httpPost($accountLoginURL, $accountLoginPostData); $current->httpPost($followFriend, $followFriendData);

And even after the first line gives me a 200. The second gives me a 401.

Upvotes: 1

Views: 260

Answers (1)

Marc B
Marc B

Reputation: 360762

You can assign to and read anything you want from the $_SESSION array. It's just a regular array like any other in PHP, except for two things:

a) It's a superglobal
b) IF you've called session_start(), then PHP will auto-populate the array from whatever's in session storage (files, db, etc...), and auto-save the contents of the array upon script exit or calling session_write_close().

Upvotes: 2

Related Questions