简体   繁体   English

PHP会话变量在服务器上不起作用

[英]php session variables not working on server

i have a problem with my website on server, 我的服务器上的网站有问题,
I am new to php 我是php新手

my login page contains the following code: 我的登录页面包含以下代码:

    session_set_cookie_params(0, '/', 'marutinrutyakala.co.uk'); 
    session_start(); 
    $_SESSION['name']= $adminname; 
    $_SESSION['login']=true; 
    $_SESSION['start']=time(); 
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=performance.php">';

now on performance.php the code is 现在在performance.php上,代码是

    session_start(); 
    if(!isset($_SESSION['login'])) 
    { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">'; }

Page code to execute here........ 要在此处执行的页面代码........

This code worked fine on local host but fails on server...... 此代码在本地主机上工作正常,但在服务器上失败...

please help.... 请帮忙....

Some things to try: 可以尝试的一些事情:

From the documentation of session_set_cookie_params : session_set_cookie_params文档中:

The effect of this function only lasts for the duration of the script. 此功能的效果仅在脚本期间持续。 Thus, you need to call session_ set_cookie_params() for every request and before session_start() is called. 因此,你需要调用session_ set_cookie_params()为每个请求和之前session_start()被调用。

So your performance.php should probably be: 因此,您的performance.php可能应该是:

session_set_cookie_params(0, '/', 'marutinrutyakala.co.uk'); 
session_start(); 
if(!isset($_SESSION['login'])) 
{ echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">'; }

Check the domain name of the server. 检查服务器的域名。 You are explicitly stating that your session cookie is only for the maruntinrutyakala.co.uk domain: is that the correct domain? 您明确声明您的会话cookie仅适用于maruntinrutyakala.co.uk域:这是正确的域吗?

Try without the session_set_cookie_params line, does it work then? 尝试在没有session_set_cookie_params行的情况下起作用吗?

Check your PHP error log : does an error appear there? 检查您的PHP 错误日志 :那里是否出现错误?

Use the following code in top of the page 在页面顶部使用以下代码

ob_start();

This function will turn output buffering on. 此功能将打开输出缓冲。 While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. 当输出缓冲处于活动状态时,脚本(头文件除外)不发送任何输出,而是将输出存储在内部缓冲区中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM