Problem using $_SESSION in PHP 7.1.10

Asked

Viewed 1,985 times

5

I have two servers running PHP, one in version 5.4.45 and another 7.1.10.

When running the files below at the same url, only the older version of PHP displays the values of the "test" session. In the version 7.1.10 the Array is displayed empty. Someone’s been through this trouble?

teste1.php

session_start();

$_SESSION['nome'] = 'teste';

teste2.php

session_start();

print_r($_SESSION);

// 7.1.10 
// Array();


// 5.4.45
// Array ( [nome] => gabriel );
  • In version 7.1.10 appears what ?

  • The empty array, already in version 5 appears the array with "test"

  • Aqui ta funfano -> http://sandbox.onlinephpfunctions.com/code/8fd64022c78c90f8154b137aa4b719041eb98d38

  • There’s something wrong, how can it be gabriel was assigned teste in the session?

  • @Magichat here ta giving teste kk

  • @Francis I saw...

  • I suggest you present images of the execution of both versions, preferably calling phpinfo() in order to be able to distinguish directly each.

  • Most of these errors is due the session is configured after the HTML Header. Puts all php calls before any HTML.

Show 3 more comments

1 answer

1

There is a bug related to the xampp version, i.e., x86 or x64 bits.

"I have a system with x64 bit windows and I installed a xampp with php7, but it was x86. This was a reason for that error, apache fails. Now I have separately installed apach2.4 (x64) and PHP7.0.1 which is working perfectly now."

Other reports of the same error: https://forum.imasters.com.br/topic/547112-erro-de-session-no-php-7/

Possible solution:

session.save_handler = files
session.save_path="C:\xampp\tmp"
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies=0
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

A programmer said that there is an error in php.ini. https://www.sitepoint.com/community/t/php-7-session-start-not-working/211635/4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.