Search code examples
phpphpstormsession-cookies

Retain session between PHP HTTP Requests in PhpStorm


I recently started setting up PhpStorm with Xdebug and so far running and debugging scripts works perfectly.

Now I want to debug a script which requires the user to be logged in (by a PHP session). My initial idea was to create a separate PHP HTTP Request logging the user in. The problem is that the PHP session is not retained between PHP HTTP Requests, so $_SESSION is always empty.

Do you have any idea why this happens (my guess is that the session cookie doesn't get stored) and how do I fix this?

Additional information:

  • The web server is running on a Linux machine on my local network.
  • I'm using PHP 7.1, PhpStorm 2018.2.2 and Xdebug 2.6.1

Thanks in advance.


Solution

  • This is not currently possible using Run/Debug Configurations nor using the HTTP Client with .http files.

    The solution is to use the deprecated REST Client under Tools > HTTP Client > Test RESTful Web Service. There you can set the PHP session cookie manually by navigating to the tab Cookies, clicking the plus on the right and copying the values from your browser.

    Copy the PHP session cookie by right clicking your page in your browser, clicking Inspect page and navigating to the tab Application, in the left menu select Cookies then click on your server address and copy the information of the cookie with name PHPSESSID (or your custom cookie name specified in your servers php.ini).

    A feature request for cookies in the HTTP Client is already subitted here.

    Hope this helps. -Minding