Log in

View Full Version : Working with vBulletin cookies..


Velocd
12-08-2002, 03:31 PM
I'm attempting to make a hack that if you are a guest, and you visit the forum without having a cookie set (or it is expired), you will be redirected to another page requesting alittle info for quick registration.

I can do this easily with a cookie javascript, but I'm wondering how to integrate it with PHP instead.

The code would reside in the global.php, and then make a couple checks:

1. If the viewer is not registered.
2. If the vBulletin cookie for last visit is greater than 1 day, probably using the cookie bblastvisit.

If both return true, then the following line of code is executed:

eval("dooutput(\"".gettemplate('guest_register')."\");");


And some template like that, not necessarily with that name, is opened. This makes it much more simple than creating a javascript and opening up a separate .html or .php file when the body has loaded.

My only problem is figuring out how to do this, or if my logic is right.

Here is my test run (as ridiculous as it might be) ;)


$dayvalue = 86400;

if($bbuserinfo[userid] == 0){
if($HTTP_COOKIE_VARS['bblastvisit'] == "" || $HTTP_COOKIE_VARS['bblastvisit'] + $dayvalue < date()){
eval("dooutput(\"".gettemplate('guest_register')."\");");
}
}


Does any of this seem plausible? :p

Velocd
12-08-2002, 04:06 PM
I just tried it out, and the condition for no cookie being set returns true if none has really been set, but if it has expired I can't seem to get the check to work. Which must mean something in this part of the code:
$HTTP_COOKIE_VARS['bblastvisit'] + $dayvalue < date()){

Is wrong... :ermm:

Chris M
12-08-2002, 04:38 PM
Shouldnt that be:

$HTTP_COOKIE_VARS['bblastvisit'] + $dayvalue < vbdate()){

??

Satan

Velocd
12-08-2002, 05:19 PM
It's more or less the logic of that condition, not whether its vbdate() or date() (and using just plain date() actually gives you a parse error)...

vbdate() just puts it in the vBulletin time format, but I'm just trying to get the unix timestamp of the present date, then compare it with the "bblastvisit" timestamp+1 day to see if it has been over 1 day since the guest last visited.

/me falls over :dead:

Velocd
12-09-2002, 12:14 AM
I'm still having some issues with this, if anybody would be so kind to help I'd really appreciate it ;)

DrkFusion
12-09-2002, 12:53 AM
time() maybe? Neo once was telling me you subtract 8000 something minutes or something from time() and that is 24 hours past.

Don't quote me on it, but I think time() is/should be used/

Xenon
12-09-2002, 02:08 PM
Drkfusion is right bblastvisit is saved in timestamp, so you have to use time:

$HTTP_COOKIE_VARS['bblastvisit'] + 3600*24 < time()){

Velocd
12-09-2002, 02:26 PM
Fant?stico! It works great, thanks for the help Drkfusion, Xenon, and Hellsatan. :p

Xenon
12-09-2002, 02:35 PM
:)
good to hear :)

you're welcome

Velocd
12-10-2002, 03:00 AM
Looks like I've got one more question (for now) concerning PHP & cookies. ;)

How is the vBulletin function for creating a cookie, vbsetcookie(), differ from the PHP preloaded function, setcookie()?

From sessions.php, I've noted that most uses of vbsetcookie() only have two arguements, the name and value. Whether it can take more, I'm not sure, but what I really need which setcookie() has is the expire arguement, which lets me set a time for when the cookie expires.

Could the following be used in vbsetcookie()?

vbsetcookie ("TestCookie", $value, time()+3600*24);


I'm just not sure of the differences between setcookie() and vbsetcookie(), that's the real question :p

Xenon
12-10-2002, 04:08 PM
well, vbsetcookies uses values you've entered in your acp like url of board and so on :)

just look into admin/functions.php the function is defined there :)