r/PHPhelp • u/Available_Canary_517 • Dec 08 '24
How to start php session through postman api request
I have a PHP application with an API that I want to test in Postman. However, the API depends on a PHP session being initialized, and it throws an error if the session is not active or a required session variable (e.g., $_SESSION['user_id']) is not set. How can I test this API in Postman by ensuring the PHP session is started and setting the user_id session variable from the Postman request?
3
Upvotes
8
u/martinbean Dec 08 '24
Why? APIs are typically stateless. One request shouldn’t know anything about any other request made before or after, and uses a token-based method such as OAuth to authorise each and every request.
2
u/allen_jb Dec 08 '24
The default PHP session implementation uses cookies to know which session belongs to a client.
Either:
See also https://learning.postman.com/docs/sending-requests/response-data/cookies/