Hi everyone, i am trying to create a login box on my home page which will enable users to log in/out on the home page to my vbulletin forums. I have successfully managed to create a log in box - it works! BUT once logged in it remains the same. I would love to know how to make it changed once logged in to display your username and a log out button.
Here is the code i am currently using:

<!--Login Form-->
			
			<form action="" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
			<input type="hidden" name="redirect" value="" />
<script type="text/javascript" src=""></script>
<table border="0" cellpadding="0" cellspacing="3">

<tbody align="left"><tr>
<td ><label for="navbar_username">User Name</label></td>
<td><input class="bginput" style="font-size: 11px;" name="vb_login_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" type="text"></td>
</tr>
<tr>
<td ><label for="navbar_password">Password</label></td>

<td><input style="font-size: 11px;" name="vb_login_password" size="10" accesskey="p" tabindex="102" type="password"></td>
</tr><tr>
<td><input value="Log in" tabindex="104" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" type="submit"></td>
<td colspan="2" nowrap="nowrap"><label for="cb_cookieuser_navbar"><input name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" type="checkbox">Remember Me?</label></td>
</tr>
<tr>
  <td colspan="2">
<a href="">Forgot Password?</a><p></td>
</tr>
<tr><td colspan="2">
<a href="">Register</a></td></tr>
</tbody></table>
<input name="s" value="" type="hidden">
<input name="do" value="login" type="hidden"> 
<input name="vb_login_md5password" type="hidden">
<input name="vb_login_md5password_utf" type="hidden">
		</form>
			
			<!--/Login Form-->

Every bit of help would be much appreciated.
Many Thanks.

Dani AI

Generated

Short answer: the forum must be initialised before you output anything. The vBulletin bootstrap (global.php) sets cookies and session data, so include it with a full PHP open tag at the very top of your page (no whitespace/BOM before it), then check the $bbuserinfo array to decide whether to show the login form or the “welcome / logout” line. The error you quoted — "Unable to add cookies, header already sent" — means some output was sent before vBulletin tried to set cookies.

A minimal, safe pattern (put this at the very top of the file; save file as UTF‑8 without BOM and use <?php not <?):

<?php
// No output above this line
require_once __DIR__ . '/../forums/global.php'; // adjust path to your /forums folder

if (!empty($bbuserinfo['userid'])) {
    $username = htmlspecialchars($bbuserinfo['username'], ENT_QUOTES, 'UTF-8');
    echo 'Welcome back, ' . $username . ' [<a href="/forums/member.php?do=logout">Logout</a>]';
} else {
    // echo or include the login form that posts to /forums/login.php
}

Troubleshooting checklist

  • Replace any short tags (<?) with <?php.
  • Remove stray whitespace or new lines before the opening <?php (or after a closing ?> in included files).
  • Save files without a UTF‑8 BOM (editors like Notepad++ show/strip BOM).
  • Make sure require_once path points to the forum’s global.php (use __DIR__ to build a reliable relative path).
  • Use !empty($bbuserinfo['userid']) or > 0 to test logged‑in status (don’t compare to == 1).
  • If you can’t restructure immediately, use ob_start() at the very top as a temporary fallback while you fix output issues.

As suggested, sessions matter — but rely on vBulletin’s $bbuserinfo rather than building a separate session layer. For the logout URL, copy the exact link used in your forum’s navbar (it may include a session/logouthash parameter) so logout works reliably.

Recommended Answers

All 7 Replies

Anybody know? HELP PLEASE!!

why not you create session for this...
then you can check whether session is there or not...if ,you can print username and logout ..if session is not there the display normal login box...
if your requirement is something else than my post,,let me know...

I understand where you are coming from - that is what i wanted to do. But i am a noobie! to this programming so do you know the code that i would use?
Many Thanks

go through this url..code yourself for your requirement..if any errors occur,then let do post here..

My problem is that vbulletin is different to normal log in. I have got the log in bit right but wanted to know how to change to log out once logged in. Do you use the if...else... - if so, how would you do it is it "if [member].."??
Many Thanks

I have tried creating some code but it is not working here is the code:

<?php 
		if($member){

// output some text
echo 'Username:
'.$info["username"].'
Registered on:
'.$info["regdate"];

// if the user ISN'T logged in
}else{

// output an error
echo 'Please Log in';}
?>

I am not sure what you have to type in for it to work with vbulletin. I am completely stuck!! Really need help!
Thanks to everyone who helps

I have made some progress, i have used the php "if & "else" to display login or logout. However when logged in all is fine - it displays "welcome... & logout" BUT when you are not logged in and i want the login box to appear this message appears: "Unable to add cookies, header already sent.
File: /customers/
Line: 8"

Code is below - CAN SOMEONE HELP PLEASE!
Many thanks

<?
require("global.php"); 

if ($bbuserinfo['userid']!=1) { 
$username=$bbuserinfo['username']; 
   
echo "<font face=\"verdana\" size=\"2\">&nbsp;<b>Welcome back, <font color=\"#FF3300\">$username</font>&nbsp;!</b>&nbsp;[<a href=\"">Logout</a>]</font>"; 

} else {
?>
			<form action="" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
			<input type="hidden" name="redirect" value="" />
<script type="text/javascript" src=""></script>
<table border="0" cellpadding="0" cellspacing="3">

<tbody align="left"><tr>
<td ><label for="navbar_username">User Name</label></td>
<td><input class="bginput" style="font-size: 11px;" name="vb_login_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" type="text"></td>
</tr>
<tr>
<td ><label for="navbar_password">Password</label></td>

<td><input style="font-size: 11px;" name="vb_login_password" size="10" accesskey="p" tabindex="102" type="password"></td>
</tr><tr>
<td><input value="Log in" tabindex="104" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" type="submit"></td>
<td colspan="2" nowrap="nowrap"><label for="cb_cookieuser_navbar"><input name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" type="checkbox">Remember Me?</label></td>
</tr>
<tr>
  <td colspan="2">
<a href="">Forgot Password?</a><p></td>
</tr>
<tr><td colspan="2">
<a href="">Register</a></td></tr>
<tr><td>

</td></tr>
</tbody></table>
<input name="s" value="" type="hidden">
<input name="do" value="login" type="hidden"> 
<input name="vb_login_md5password" type="hidden">
<input name="vb_login_md5password_utf" type="hidden">
		</form>
<?
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.