PDA

View Full Version : TIMENOW and access to it outside the Forum Software


CtrlAltDel
09-08-2008, 06:19 PM
I want to display a logout button to logged in users on my new custom homepage that I am writing. I have been able to recreate the logout hash, but since it is based off of appending "time()-" to the front, the value it gets is different than what the value would be when generated by login.php.

How do I get to the global TIMENOW variable that VB uses? Do I need to just include global.php into my application?

Is there another way to do this without including that entire file? Trying to avoid unnecessary bloat from 'over including' files.

TIA

Kirk Y
09-08-2008, 06:58 PM
There is no difference; vBulletin uses time() as TIMENOW.

See line 32 of init.php:
define('TIMENOW', time());


Check out line 1335 of functions.php:
$user['securitytoken'] = sha1($user['userid'] . sha1($user['salt']) . sha1(COOKIE_SALT));
$user['logouthash'] =& $user['securitytoken'];

CtrlAltDel
09-08-2008, 07:11 PM
Maybe I need to update the forum that I'm working with. As this is the code from my functions.php...


$user['securitytoken_raw'] = sha1($user['userid'] . sha1($user['salt']) . sha1(COOKIE_SALT));
$user['securitytoken'] = TIMENOW . '-' . sha1(TIMENOW . $user['securitytoken_raw']);
$user['logouthash'] =& $user['securitytoken'];


Assume:
1. myscript.php is a script outside my forum root directory
2. login.php is the standard file included in vB

Appending time() in myscript.php is going to be different than the generated one that would be generated from login.php. So when I pass the hash from one myscript.php to login.php, login.php will error out and then display a new (and correct) logout link w/proper logouthash.

If the newest version of VB has dropped this timestamping feature of the logout hash then this simplifies things dramatically.

Kirk Y
09-08-2008, 07:27 PM
Ah, I didn't realize the 3.7.3 hash now included the time (I was looking at 3.7.0).

Try including your global file. At least then the constant would be in namespace.

chdir('/path/to/forum');
require_once('global.php');

CtrlAltDel
09-08-2008, 07:48 PM
Yeah I figured I had to do that so I started playing with that.

It works all well and good, but the logout hash is not correct. I click it and then I get an error page on login.php and it then generates a logouthash that is correct.

I wonder what magical step I'm missing. Maybe I'm missing setting some cookie var, or session var.

--------------- Added 1220931509 at 1220931509 ---------------

By including the global.php shouldnt I be able to use things like $bbuserinfo inside my custom php page?

--------------- Added 1220983002 at 1220983002 ---------------

figured it out, just needed to use the right variable, $vbulletin->userinfo['logouthash']