WAMP 2.4会话不起作用

时间:2014-03-26 17:40:47

标签: php session wamp

我的计算机上安装了WAMP 2.4,但我无法使用Sessions。它们在我的实时制作服务器上运行良好

PHP.ini中

[Session]
session.save_handler = files
session.save_path = "c:/wamp/www/tmp"
session.use_cookies = 1
session.use_only_cookies = 1
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.bug_compat_42 = On
session.bug_compat_warn = On
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5

测试.php文件:

<?php
session_start();

$_SESSION[title] = 'PHP100.com';

echo $_SESSION[title];

PHP错误:

[26-Mar-2014 17:36:57 UTC] PHP Notice:  Use of undefined constant title - assumed 'title' in C:\wamp\www\session.php on line 6

[26-Mar-2014 17:36:57 UTC] PHP Stack trace:

[26-Mar-2014 17:36:57 UTC] PHP   1. {main}() C:\wamp\www\session.php:0

1 个答案:

答案 0 :(得分:1)

您在数组键周围缺少引号,将其定义为字符串。如果没有它,PHP假定您的意思是名为title的常量。但是,您没有使用该名称定义常量,这就是您看到错误的原因:

$_SESSION[title] = 'PHP100.com';
echo $_SESSION[title];

应该是:

$_SESSION['title'] = 'PHP100.com';
echo $_SESSION['title'];