F
F
ftp272012-10-06 20:24:29
PHP
ftp27, 2012-10-06 20:24:29

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>";
?>

And he doesn't want to work. Here are the server settings regarding sessions
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

5 answer(s)
H
himik, 2012-10-06
@ftp27

if after that
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
do
var_dump($_SESSION);
what outputs?

E
edogs, 2012-10-06
@edogs

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.

D
Denis, 2012-10-06
@karneds

You can check if php has write permissions to session.save_path. Ever since. Have you contacted hosting support?

X
xmoonlight, 2012-10-06
@xmoonlight

Comment. Superfluous ... In theory, it should initialize and add one automatically ...
//if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;

A
Alexander, 2014-04-15
@another_dream

2 options:
1:
SELECT
t2.*
FROM t1 INNER JOIN t2 ON t1.id = t2.owner_id
2.
SELECT
t2.*
FROM t2 WHERE t2.owner_id IN (SELECT t1.id FROM t1)
Learn the materiel :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question