2013-01-03 91 views
1

我想在我的服務器的PHP的session_start產生警告

<?php 
session_start(); 
?> 

我得到以下警告消息運行這段代碼。我從來沒有見過這樣的警告。

Warning: session_start() [function.session-start]: open(/var/chroot/home/content/00/6684400/tmp/sess_uoouukt8m6efc0nc2ar5t2vq94, O_RDWR) failed: No such file or directory (2) in /home/content/00/6684400/html/html-tweetcomments/y.php on line 2 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/00/6684400/html/html-tweetcomments/y.php:2) in /home/content/00/6684400/html/html-tweetcomments/y.php on line 2 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/00/6684400/html/html-tweetcomments/y.php:2) in /home/content/00/6684400/html/html-tweetcomments/y.php on line 2 

Warning: Unknown: open(/var/chroot/home/content/00/6684400/tmp/sess_uoouukt8m6efc0nc2ar5t2vq94, 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 

我該如何解決這個問題?

回答

2

確認,文件夾/var/chroot/home/content/00/6684400/tmp存在和PHP

是可寫的
sudo mkdir -p /var/chroot/home/content/00/6684400/tmp/ 
sudo chmod 1777 /var/chroot/home/content/00/6684400/tmp/ 

session_start()設置一個包含會話ID的cookie。在HTTP協議中,Cookie在HTTP標頭Set-Cookie中發送。

如果您發送任何輸出(包括PHP警告),則會將其寫入HTTP答案主體,PHP不再能夠發送標題。

爲了確保HTTP響應正文寫在最後,您可以在PHP腳本的開頭添加ob_start()

這會創建一個輸出緩衝區,當腳本到達結尾時它將自動刷新輸出。

參考

2

權限問題。

檢查tmp文件夾權限。使其可寫。

Failed to write session data (files). 

此外,檢查有前session_start()

1

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/00/6684400/html/html-tweetcomments/y.php:2) in /home/content/00/6684400/html/html-tweetcomments/y.php on line 2

東西沒有HTML或空白您在session_start調用之前正在打印。檢查任何迴音或HTML甚至任何空格,您的通話之前

1

線索是第一個錯誤:

open(/var/chroot/home/content/00/6684400/tmp/sess_uoouukt8m6efc0nc2ar5t2vq94, O_RDWR) 
failed: No such file or directory (2) 

它看起來就像是正在爲會議文件中引用要麼不目錄存在或不可由Web用戶(運行Web服務器的用戶)寫入。

  • 檢查目錄是否存在 - 如果沒有,則創建它。
  • 確保它可以由Web服務器用戶組寫入。

第一個錯誤是導致其餘的錯誤;

0

如果有PHP代碼之前相同的輸出,PHP代碼後移動它示例:

<script> 
...javascript code... 
</script> 
<?php 
session_start(); 
?> 

將腳本標記移到php標記後面。像這樣:

<?php 
session_start(); 
?> 
<script> 
...javascript code... 
</script> 
相關問題