PHP session not working

I rejected this question because I suspect that something messed up my settings that caused the problems and has since created a new server. I decided that finding the problem would take longer than starting a new server and setting it up. However, I'm still curious to find out what caused this, as it worked great for 3 months and just started showing these symptoms over the weekend. **

==================================================== ===============================

I have a problem with a newbie, perhaps because I have been working in other languages ​​in recent months and I just can’t understand why this is not working. I made a very simple script to test it, which looks like this:

<?php session_start();
  print_r($_SESSION);
  if(isset($_SESSION['views'])){
      $_SESSION['views'] = $_SESSION['views']+ 1;
  }
  else{
      $_SESSION['views'] = 1;
  }
  echo "views = ". $_SESSION['views'];
  echo '<p><a href="">Refresh</a></p>';

  # for testing
  var_dump($_SESSION);

?>

, , var_dump , 1. , 1.

, , PHPSESSID. , , . , , :

Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Connection  close
Content-Encoding    gzip
Content-Length  68
Content-Type    text/html; charset=utf-8
Date    Wed, 18 Jan 2012 13:03:34 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Pragma  no-cache
Server  Apache
Vary    Accept-Encoding
X-UA-Compatible IE=Edge,chrome=1

cookie :

 Cookie PHPSESSID=0e1416r7pun3pamvc7cp8mjat3

, - . Amazon EC2 linux AMI.

phpinfo():

PHP Version 5.3.6
System  Linux ip-**-**-**-** *.*.**.**-**.**.amzn1.x86_64 #1 SMP Sat Feb 19 23:42:04 UTC 2011 x86_64 
session
Session Support     enabled    
Registered save handlers    files user    
Registered serializer handlers  php php_binary wddx    
Directive   Local Value Master Value    
session.auto_start  Off Off
session.bug_compat_42   Off Off
session.bug_compat_warn Off Off
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly On  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  1000    1000
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /var/lib/php/session    /var/lib/php/session
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

, , , , . , , .

+4
3

session.use_cookies php.ini.

COOKIE.

session.use_cookies 1.

+2

, ( session_id()). , :

$_SESSION['views'] = $_SESSION['views']+ 1;

$_SESSION['views'] += 1;
+1

When you create a link to the same page you are on, the whole page is not updated. You will need to do this via JavaScript.

In HTML (or PHP echo):

<button type='button' onclick='refreshPage()'>Refresh</button>

Now install the function in JavaScript:

function refreshPage(){
document.location.reload(true);
}

When JavaScript does this, the whole page refreshes and all PHP lines are launched again.

Another way to try this is to link the link to another page and return to the first page, then the whole page will load again.

0
source

All Articles