Question

I have a WAMP 2.4 setup on my computer that I can't get Sessions working. they work fine on my live production server

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

Test .php file:

<?php
session_start();

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

echo $_SESSION[title];

PHP Error:

[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
Was it helpful?

Solution

You're missing quotes around your array key defining it as a string. Without it PHP assumes you mean a constant named title. But you don't have a constant defined with that name which is why you see that error:

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

should be:

$_SESSION['title'] = 'PHP100.com';
echo $_SESSION['title'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top