Log in

View Full Version : How do I display the user cookie information through PHP?


royli57
04-04-2004, 11:49 PM
I want to write a custom login box for my homepage. Using the navbar template, I think I can finish the login part of it. I just need to submit to the login.php using a form.



The tricky part is emulating the information once the user is logged in. I want to use PHP to find the information set by the cookie. When you log into the standard forums, the login box contains this information:



Welcome, royli57.

You last visited: Today at 05:15 PM

Private Messages: 0 Unread, Total 0.

So I want to display these variables using PHP. The problem is that the variables are given as



$vbphrase[welcome_x]

$vbphrase[last_visited_x_at_y]

$vbphrase[private_messages_nav]

Within the navbar template. Is there a way I can use these variables directly? If not is there a way I can access the cookie and return the information from there?



Thanks



Roy

nsanden
04-05-2004, 05:51 AM
I do pretty much the same thing on my site. The way I did it was first check to see if the visitor has $_COOKIE['bbuserid'] set. If that is set, it means he is logged in, in which case you don't want to show the login form.


if($_COOKIE['bbuserid']) {
//show login form
} else {
//show user info
}


For the login form i made my own but made sure to include the required hidden input fields VB uses and post the script to VB's login.php page.

For the user information i ran a query against the vb_user table based on the $_COOKIE['bbuserid'] id.

Hope that helps.

royli57
04-05-2004, 07:07 PM
Perfect! Just what I needed.

Roy