PHP 仅在 GoDaddy 上存在会话问题(警告:session_start():无法发送会话 cookie)

PHP Session issue only on GoDaddy (Warning: session_start(): Cannot send session cookie)

我目前正在为 GoDaddy 主机上的客户开发用户注册系统。

我之前在 Hostgator 上和在 OS X 上的 PHP 测试服务器上进行本地测试时从未遇到过此类问题。

这也是一个相当简单的脚本。 common.php 访问 MySQL 数据库,所有页面(登录、注册等)都包含 common.php。会话在用户登录等时开始

我在页面顶部看到以下错误:

Warning: session_start(): open(/home/content/10/12114910/tmp/sess_trmok9fgtb527mjp21a76shf54, O_RDWR) failed: No such file or directory (2) in /home/content/10/12114910/html/common.php on line 86

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/content/10/12114910/html/common.php:86) in /home/content/10/12114910/html/common.php on line 86

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/content/10/12114910/html/common.php:86) in /home/content/10/12114910/html/common.php on line 86

页面底部出现以下错误。

Warning: Unknown: open(/home/content/10/12114910/tmp/sess_trmok9fgtb527mjp21a76shf54, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0

再次声明,这只是 GoDaddy 的问题。我的客户最初使用的是 Windows 托管服务,但这根本无法正常工作,我将它们切换到了 Linux 托管服务。

他们使用的是 PHP 版本 5.3,我将其更改为 5.4,但我仍然没有运气。

我从来没有弄乱过 php.ini 文件。我需要创建一个吗?我听说将它上传到 public_html 文件夹会覆盖服务器上的文件夹,即使我们使用的是共享主机计划。

我是否还需要 SSH 访问权限才能创建 tmp 文件夹并为其设置适当的权限?

这通常很容易解决糟糕的提供商(顺便说一句,我不推荐 GoDaddy)。

以下是我的修复方法,希望对您有所帮助。

Step 1: Make a directory and call it _sessions or something of that nature.

Step 2: Give it a chmod of 775 so that the web server can write to it.

Step 3: On the first script that runs, right at the top place session_save_path("./_sessions");

Step 4 (optional, but recommended): Add either deny from all in a .htaccess file to prevent people from getting to the directory, or simply chmod 776.

在此处了解有关 session_save_path() 的更多信息:php.net/session_save_path