ds3422222 2019-05-30 12:10
浏览 86

在不同目录中保存php会话的问题

I'm trying really hard to save my sessions in different directory. I have a shared server in OVH. Default session save path is /tmp, and I want to change it.

In my root directory I have www folder which is my main website folder. I created 'sessions' folder next to it, chmoded 777. When I'm doing print_r(scandir('/home/expressptp/sessions/')); i'm getting files just fine, but when I try to session_save_path('/home/expressptp/sessions'); nothing ever appears there.

Full code looks something like this:

    session_save_path('/home/expressptp/sessions');
    session_start();

    echo session_id();
    $_SESSION["test"] = "test";

    echo session_save_path(); //that prints good path

But the problem is that in folder sessions there are no sessions :(

I tried everything. I put 'sessions' folder in 'www', chmod 777, setting path with realpath(dirname($_SERVER['DOCUMENT_ROOT']), etc.

If you have any ideas I will be grateful.

  • 写回答

1条回答 默认 最新

  • duandiao3961 2019-05-30 12:56
    关注

    Are you absolutely sure nothing in your code has begun outputting ("echo" or html tags or text) to the browser before you try this code?

    Many times session/header/cookie functions do not work as expected just because of that...

    Also, many host providers do restrict these kind of configurations, have you checked if the session_save_path() function is disabled, or if OVH explicitly prohibits this configuration change?

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大