Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to a PHP website with Node.js and keep session

I'm making a testbench with Test'em and Mocha (that run on node.js) in order to test a PHP website.

What I want is to request some URL (e.g http://www.my-website/test.php) and get the http status code as well as the content returned.

I'm doing it with the node.js Request module.

The problem is:

I need to be authenticated to access this page, otherwise I'm redirected to the login page.

So, does it exist a way to log in my application through Node.js and keep the session open to be able to chain tests on any pages I want?

I was thinking on get the PHPSESSID on login request if it is possible. Do you thing it is a good direction ?

Any help would be much appreciated.

Thank you, have a nice day :)

Michaël

like image 705
Michaël Avatar asked Oct 15 '25 16:10

Michaël


1 Answers

If you set jar: true in your options or use your own custom cookie jar, then request will remember cookies set by the server so that you can keep your session between requests.

like image 58
mscdex Avatar answered Oct 18 '25 10:10

mscdex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!