如何在Wordpress中使用session_start? [英] How to use session_start in Wordpress?
问题描述
我正在创建一个双语站点,并决定使用session_start
通过以下方式确定页面的语言:
I'm creating a bilingual site and have decided to use session_start
to determine the language of the page using the following:
session_start();
if(!isset($_SESSION['language'])){
$_SESSION['language'] = 'English'; //default language
}
此问题是它与Wordpress冲突,我得到以下信息:
The problem with this is that it clashes with Wordpress and I get the following:
警告:session_start()[function.session-start]:无法发送会话 cookie-已发送的标头(输出始于 /home/neurosur/public_html/v2/wp-content/themes/default/header.php:8) 在/home/neurosur/public_html/v2/wp-content/themes/default/region.php中 在第13行
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/neurosur/public_html/v2/wp-content/themes/default/header.php:8) in /home/neurosur/public_html/v2/wp-content/themes/default/region.php on line 13
有没有办法解决这个问题?
Is there a way to get around this?
推荐答案
将您的代码移动到header.php文件的顶部. 并检查会话是否已经存在:
Move your code to the top of header.php file. And check if session already exists:
if(session_id() == '')
session_start();
your code here...
这篇关于如何在Wordpress中使用session_start?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!