Topic: "Not logged in" - weird cookie problem

In short I want to use my existing log in script to also log users into punBB automatically.
I'm using the following code:

define('PUN_ROOT', './forum/');
global $db, $pun_user, $pun_config;
require PUN_ROOT.'include/common.php';

pun_setcookie ('2', '71f8e7976e4cbc4561c9d62fb283e7f788202acb', '86400');

It even adds the username of the userid "2" to the "online" list. That proves that the userid and passwordhash are correct.  However, I am not being logged in.  There are no errors whatsoever, its setting the cookie, that much is for sure, but for some reason punBB tells me I'm not logged in.

I'm sure others have run into this problem...can anyone help me?

Re: "Not logged in" - weird cookie problem

Setting the cookie doesn't change pun_user: that takes another pageview.

3 (edited by Maxtrix 2007-03-21 22:38)

Re: "Not logged in" - weird cookie problem

What's pun_user, and why would I need to change it?  I mean setting the login cookie should be enough, shoulnt it?

Also, could it have something to do with where the punBB cookie it set? At which path?
I'm setting it in the root dir (domain.com/login.php) and my forum is in domain.com/forum/

Re: "Not logged in" - weird cookie problem

$pun_user? The global variable user data is stored in?
What's telling you that you're not logged in?

Re: "Not logged in" - weird cookie problem

Well, it displays "You are not logged in."

What does $pun_user have to do with logging people in?  I fail to see the connection here.  What else must I do apart from setting the cookie with pun_setcookie(); ?

Re: "Not logged in" - weird cookie problem

I'm not clear what the situation here is
Are you setting the cookie on one page and then navigating to the forums?

7 (edited by Maxtrix 2007-03-22 00:56)

Re: "Not logged in" - weird cookie problem

Ok, Ill explain it a little simpler. Sometimes it helps to cut all the un-needed crap away and make the problem as simple as it can be.  I have done that now.

Forget everything I said above and look at this code placed inside the forum dir called "login2.php":

<?php

define('PUN_ROOT', './');
global $db, $pun_user, $pun_config;
require PUN_ROOT.'include/common.php';

$userid = 2;
$pass = pun_hash("none");
pun_setcookie ($userid, $pass, 86400);

?>

I go to login2.php and get no errors whatsoever.  I then return to index.php of the forum, and SHOULD be logged in, however I'm not logged in.  What am I doing wrong? Userid "2" and hashpassword "71f8e7976e4cbc4561c9d62fb283e7f788202acb" are correct values, I checked via phpmyadmin.

Re: "Not logged in" - weird cookie problem

The expiration value needs to be time() + 86400: that's the way the setcookie function works, based on unix timestamps
Basically, you're setting a cookie that your browser immediately rejects as being too old

Re: "Not logged in" - weird cookie problem

Omg, now it works.  Unbeliveable.  Well, just goes to proove that I should learn cookies :S
I've always worked with sessions because I thought original cookies as outdated.  Thanks a lot!