Answer the question
In order to leave comments, you need to log in
Sessions in PHP
This is not the first time I have encountered such a problem, but on this project they were needed at the request of the customer. On hosting, sessions do not work for a cut.
I write this simple code:
<?php
session_start();
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
echo "Вы обновили эту страницу ".$_SESSION['counter']++." раз. ";
echo "<br><a href=".$_SERVER['PHP_SELF'].">обновить</a><br>";
?>
Session Support | enabled |
Registered save handlers | files user memcache sqlite |
Registered serializer handlers | php php_binary wddx |
Directive | local value | Master Value |
---|---|---|
session.auto_start | Off | Off |
session.bug_compat_42 | On | On |
session.bug_compat_warn | On | On |
session.cache_expire | 180 | 180 |
session.cache_limiter | nocache | nocache |
session.cookie_domain | no value | no value |
session.cookie_httponly | Off | Off |
session.cookie_lifetime | 0 | 0 |
session.cookie_path | / | / |
session.cookie_secure | Off | Off |
session.entropy_file | no value | no value |
session.entropy_length | 0 | 0 |
session.gc_divisor | 100 | 100 |
session.gc_maxlifetime | 1440 | 1440 |
session.gc_probability | one | one |
session.hash_bits_per_character | 4 | 4 |
session.hash_function | 0 | 0 |
session.name | PHPSESSID | PHPSESSID |
session.referer_check | no value | no value |
session.save_handler | files | files |
session.save_path | /tmp/php_sess | /tmp/php_sess |
session.serialize_handler | php | php |
session.use_cookies | On | On |
session.use_only_cookies | Off | Off |
session.use_trans_sid | 0 | 0 |
Answer the question
In order to leave comments, you need to log in
if after that
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
do
var_dump($_SESSION);
what outputs?
Before <? php no empty spaces? bom characters for example? Session number cookies may not go away if so.
Is the time on the server correct? Session number cookies can be deleted immediately if so.
You can check if php has write permissions to session.save_path. Ever since. Have you contacted hosting support?
Comment. Superfluous ... In theory, it should initialize and add one automatically ...
//if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question