How to configure session.save_path inside php.ini for webpack4 based website?

江枫思渺然 提交于 2019-12-02 09:16:33

So I finally made it, here's what I had to do overall! I worked in the latest, no-install XAMPP and on ZURB Foundation 6.4 ZURB template project.

To establish a session across domains via AJAX, one has to make the following configurations:

Set your headers through the called php skripts, like so:

Header("Access-Control-Max-Age: 360");
Header("Access-Control-Allow-Credentials: true");
Header("Access-Control-Allow-Methods: *");
Header("Access-Control-Allow-Headers: Origin");
Header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
Header("Access-Control-Allow-Origin: "http://localhost:PORT FROM WHICH AJAX CALL IS  PERFORMED");

You can also do this inside your httpd.conf in your directory section, like so:

Header set Access-Control-Allow-Origin "http://localhost:8000"

and so on...

Then, you need to go into your php.ini and configure the following for your session: session.save_path = "D:\Path\To\src\Session"

Then, assuming you left everything else in default setting, you need to configure the following cookie parameters like so:

session.cookie_lifetime = 3600
session.cookie_domain = localhost 

(if your working with localhost domain)

Then, if youre using AJAX, you have to manually set the object doing the invokation to submit credentials, otherwise browsers dont send cookies across domains, like so:

   $.ajax({
      type:"POST",
      url: 'http://localhost:8099/test3.php',
      xhrFields: {
     withCredentials: true
     }
  }).then((response) => {
    console.log(response)
  })
}

The xhrFields - withCredentials is the very important part here! If its not set to true, no cookie will be transmitted across domains.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!