简体   繁体   中英

php session variables not working on server

i have a problem with my website on server,
I am new to 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

    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 :

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.

So your performance.php should probably be:

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?

Try without the session_set_cookie_params line, does it work then?

Check your PHP error log : does an error appear there?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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