Page 1 of 1

[SOLVED] New ways of newbies(me) breaking sessions!

Posted: Wed Feb 22, 2006 2:20 pm
by InterHat
I'm a perl programmer mostly and I dabble in ASP.net. I'm just getting into PHP, but I have a tendancy to break things... a lot. I've fixed most of the problems and everything was running smoothly before the holiday. However, I must've been bashing away at the keyboard in a semi-drunken haze on friday because what I remember working is now failing miserably! I've done something and now my sessions don't even work!

I was playing around with CAPTCHA_Text and it was working perfectly at home. I got it to recognize me entering various randomly generated CAPTCHAs which stored the phrase in a session var. Today everything went awry and I'm getting some odd errors. Specifically:

Code: Select all

<?php

// initialize a session
session_start();

// increment a session counter
$_SESSION['counter']++;

// print value
echo "You have viewed this page " . $_SESSION['counter'] . " times";

?>
Gives me:
"Notice: Undefined index: counter in C:\www\Apache2\htdocs\testsessions.php on line 7
You have viewed this page 1 times"

No matter how many times I refresh it. I'm using mozilla's web developer toolbar and I'm seeing no cookies, HOWEVER there are definitely sessions being stored in my directory. My captcha script is also creating images based on session IDs when I run it(and not deleting them properly, but that may be a permissions issue). Obviously, I need cookies to propogate the session so I can keep some sort of state. I'm running Apache 2.0.55 and PHP 5.somethingoranother on XP SP2.

My PHP.ini looks like this:

Code: Select all

[Session]
session.save_handler = files
session.save_path = "C:\PHP\sessions"
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 = localhost

session.serialize_handler = php

session.gc_probability = 1
session.gc_divisor     = 1000

session.gc_maxlifetime = 1440
session.bug_compat_42 = 1
session.bug_compat_warn = 1
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 = 1
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
Any help is appreciated!

Posted: Wed Feb 22, 2006 3:16 pm
by feyd
I'm happy to report this problem has nothing to do with sessions. :)

change

Code: Select all

$_SESSION['counter']  ;
to

Code: Select all

$_SESSION['counter'] = (isset($_SESSION['counter']) ? intval($_SESSION['counter'])+1 : 1);

Posted: Wed Feb 22, 2006 3:40 pm
by InterHat
That got rid of the error, but I still have a session problem.

(I added some code to output the session id)

"3bbb4bm4frbk39jonsekee8t2crq4ktu
You have viewed this page 1 times"

"gfbbmnhsovhfutv9r8ss41ssch8dcarr
You have viewed this page 1 times"

On refresh, it sees me as a new user each time and I'm not seeing any cookies still, but I know cookies do work since I have plenty of cookies in my user documents and settings.

Edit: And thanks for your help... and your sha256 code, it saved me a ton of time and piece of mind!

Posted: Wed Feb 22, 2006 3:59 pm
by feyd
Since you've set your install to only use cookies if the cookie doesn't take php will issue a new id. You may need to alter the path and domain settings you've changed back to what they were.

Posted: Wed Feb 22, 2006 4:04 pm
by InterHat
feyd wrote:Since you've set your install to only use cookies if the cookie doesn't take php will issue a new id. You may need to alter the path and domain settings you've changed back to what they were.
I am a moderately sized pile of dumb, removing localhost from the session domain fixed everything. Thanks again!
Editting the first post to say solved.