How to create login forphpbb3 on website

Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here.
Forum rules
Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here. Feature requests are closed.
uwed
Registered User
Posts: 4
Joined: Mon May 28, 2007 1:00 am

How to create login forphpbb3 on website

Post by uwed »

Hi Guys,

Bare with me if that's the wrong forum, it is sometimes hard to work out where to ask what.

I was wondering if there is any guidance available how to create a user login for phpBB3 on a separate website? We have done that already with phpbb2, but obviously things have changed and I am a little bit lost here... Is there anyone who can tell what to do?

Thanks,
Uwe

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: How to create login forphpbb3 on website

Post by Highway of Life »

My favorite piece of code:

Code: Select all

if (!$user->data['is_registered'])
{
    if ($user->data['is_bot'])
    {
        // the user is a bot, send them back to home plate...
        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    }
    // the user is not logged in, give them a chance to login here...
    login_box('', 'LOGIN');
} 
Image

uwed
Registered User
Posts: 4
Joined: Mon May 28, 2007 1:00 am

Re: How to create login forphpbb3 on website

Post by uwed »

Hi,

Thanks a lot for your reply! Could you please explain in a little bit more detail how to use that code on separate php (non forum) page? From what I see I guess this code checks whether the user is logged in or not. But how do I create the login itself?

Thanks,
Uwe

uwed
Registered User
Posts: 4
Joined: Mon May 28, 2007 1:00 am

Re: How to create login forphpbb3 on website

Post by uwed »

Hi,

What I have done so far is that I added the following few lines of phpbb3 code to the page where I need the login dialogue:

Code: Select all

<?php 
	//phpbb3 login, user session management
	$phpbb_root_path = './vernon_forum/';
	$returnAddress ='../index.php';
	//including phpBB3 stuff	
	define('IN_PHPBB', true);
	$phpEx = substr(strrchr(__FILE__, '.'), 1);
	include($phpbb_root_path . 'common.' . $phpEx);
	include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

	// Start phpbb3 session management
	$user->session_begin();
	$auth->acl($user->data);
	$user->setup('viewforum');
?>
  • $phpbb_root_path = './vernon_forum/';
    This needs to be adjusted to the file structure in which the document is located
  • $returnAddress ='../index.php';
    This needs to be relative to the position of the forum!


The login stuff looks like that:


Code: Select all

<?php


if (!$user->data['is_registered']) {
	echo '<div id="login">';
	echo '<form method="post" action="'.$phpbb_root_path.'/ucp.php?mode=login" class="headerspace">';
			
	echo '		<ul>';
	echo '		<li><label for="username">Username:</label>&nbsp;<input type="text" name="username" id="username" size="5" class="inputbox" title="Username" />  </li>';
	echo '			<li><label for="password">Password:</label>&nbsp;<input type="password" name="password" id="password" size="5" class="inputbox" title="Password" /></li>';
	echo '			<li><label for="autologin">Log me on automatically each visit <input type="checkbox" name="autologin" id="autologin" class="checkbox" /></label> <input type="submit" name="login" value="Login" class="button2" /></li>';
	echo '			</ul>';
	echo '			<input type="hidden" name="redirect" value="'.$returnAddress.'">';
	echo '			</fieldset>';
	echo '		</form>';
	echo '	</div>';

}

if ($user->data['is_registered']) {
	echo '<a href="'.$phpbb_root_path.'/ucp.php?mode=logout'.$SID.'">Logout</a>';

}

?>
Everything works fine but the logout link. Obviously I need to add the 'sid' to the logout link. Anyone any idea how can achieve that?

Thanks,
Uwe

uwed
Registered User
Posts: 4
Joined: Mon May 28, 2007 1:00 am

Re: How to create login forphpbb3 on website

Post by uwed »

Hi,

I seem to use this post as my personal brain storm area :D

Anyway, I just worked out how the log out link shoud look like or at least nearly shoudl look like.

Code: Select all

echo '<a href="'.$phpbb_root_path.'/ucp.php?mode=logout&sid='.$user->data['session_id'].'&redirect='.$returnAddress.'">Logout</a>';
The only problem to solve now is how to tell the log out process which page to redirect to. Again: Anyone any ideas?

uwe

1337blaze
Registered User
Posts: 1
Joined: Sun Jun 10, 2007 10:27 pm

Re: How to create login forphpbb3 on website

Post by 1337blaze »

hey uwed, you can do the logout redirect with a very simple code change in the ucp.php file.

Open up ucp.php, and change line 95 to:

Code: Select all

      ## LOGOUT REDIRECT HACK  -- BEGIN ##
		$redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");
		meta_refresh(3, append_sid($redirect));
		## LOGOUT REDIRECT HACK  -- END ##
Line 95 looks like:

Code: Select all

meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")));
Now you can redirect the same way you do with login.

Pliniusneo
Registered User
Posts: 1
Joined: Tue Jul 10, 2007 7:14 pm

Re: How to create login forphpbb3 on website

Post by Pliniusneo »

If you do that, and you want your redirect link to work properly, you should change line 100 (it's line 100 if you've directly copy-pasted 1337blazes mode over line 95) to:

Code: Select all

		$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($redirect) . '">', '</a> ');
otherwise you will be redirected to the right place, but if you click the link, you will go to the forums instead.

(this is the first time I've changed a code in phpbb so I hope it works ^^)

I was searching for the same phpBB3 integration for my site, and what I have made is:

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './phpBB3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(); ?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Nieuwe pagina 1</title>

</head>

<body>
<?php

if($user->data['is_registered'])
{
echo("Hi " . $user->data['username'] . "!<br /><br /><a href=" . $phpbb_root_path . 'ucp.php?mode=logout&redirect=../index.php' . '&sid=' . $user->data['session_id'] . ">Logout</a>");
}
else
{
echo('You are a guest <br><form action="phpBB3/ucp.php" method="post" enctype="multipart/form-data">
<label for="username">Username:</label><input type="text" name="username" /><br />
<label for="password">Password:</label><input type="password" name="password" /><br />
<input type="hidden" name="redirect" value="../index.php" />
<label for="username">Automatic login:</label><input type="checkbox" name="autologin" id="autologin" class="checkbox" />
<input type="submit" value="login" name="login" />
</form>');
} ?>

</body>

</html>
with the little mod from 1337blaze it works just fine for me.

bilo182
Registered User
Posts: 1
Joined: Mon Aug 13, 2007 5:40 pm

Re: How to create login forphpbb3 on website

Post by bilo182 »

hei... i just made the modifications u said below .. but it doesn't redirect me to the index of the site.. (it redirects me in the index of the forum) :(
here are my codes:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
and

Code: Select all

<?php

if($user->data['is_registered'])
{
echo("<span class='font-12'>Hi <b>" . $user->data['username'] . "</b>!</span><br><br><a href=" . $phpbb_root_path . 'ucp.php?mode=logout&redirect=../index.php' . '&sid=' . $user->data['session_id'] . " class='menulink'>Logout</a>");
}
else
{
echo('<span class="font-12">You are a guest</span><br><form action="forum/ucp.php" method="post" enctype="multipart/form-data">
<table border="0" cellpadding="2" cellspacing="0">
<tr><td>
<span class="font-12">Username:&nbsp;</span><input type="text" name="username" class="user" size="10"></td></tr>
<tr><td>
<span class="font-12">Password:&nbsp;</span><input type="password" name="password" class="pass" size="10"></td></tr>
<tr><td>
<input type="hidden" name="redirect" value="../index.php">
<span class="font-12">Automatic login:&nbsp;</span><input type="checkbox" name="autologin" id="autologin" class="checkbox"></td></tr>
<tr><td align="center">
<input type="submit" value="Login" name="login"></td></tr></table>
</form>
');
} ?>
i am out of ideas.. :(

Skash
Registered User
Posts: 2
Joined: Sat Nov 25, 2006 3:04 pm

Re: How to create login forphpbb3 on website

Post by Skash »

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = '/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
if (!$user->data['is_registered']) {
   echo '<div id="login">';
   echo '<form method="post" action="'.$phpbb_root_path.'/ucp.php?mode=login" class="headerspace">';
         
   echo '      <ul>';
   echo '      <li><label for="username">Username:</label>&nbsp;<input type="text" name="username" id="username" size="5" class="inputbox" title="Username" />  </li>';
   echo '         <li><label for="password">Password:</label>&nbsp;<input type="password" name="password" id="password" size="5" class="inputbox" title="Password" /></li>';
   echo '         <li><label for="autologin">Log me on automatically each visit <input type="checkbox" name="autologin" id="autologin" class="checkbox" /></label> <input type="submit" name="login" value="Login" class="button2" /></li>';
   echo '         </ul>';
   echo '         <input type="hidden" name="redirect" value="'.$returnAddress.'">';
   echo '         </fieldset>';
   echo '      </form>';
   echo '   </div>';

}

if ($user->data['is_registered']) {
   echo '<a href="'.$phpbb_root_path.'/ucp.php?mode=logout'.$SID.'">Logout</a>';

}

?>
This works to a point, I no longer get errors YIPPIE! but I'm having trouble reading those blasted sessions and cookies! and the .$returnAddress isn't working either well, time to save up and hope for someone to come help and save me.

shaythong
Posts: 4
Joined: Thu Jul 20, 2006 11:44 pm

Re: How to create login forphpbb3 on website

Post by shaythong »

Skash wrote:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = '/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
if (!$user->data['is_registered']) {
   echo '<div id="login">';
   echo '<form method="post" action="'.$phpbb_root_path.'/ucp.php?mode=login" class="headerspace">';
         
   echo '      <ul>';
   echo '      <li><label for="username">Username:</label>&nbsp;<input type="text" name="username" id="username" size="5" class="inputbox" title="Username" />  </li>';
   echo '         <li><label for="password">Password:</label>&nbsp;<input type="password" name="password" id="password" size="5" class="inputbox" title="Password" /></li>';
   echo '         <li><label for="autologin">Log me on automatically each visit <input type="checkbox" name="autologin" id="autologin" class="checkbox" /></label> <input type="submit" name="login" value="Login" class="button2" /></li>';
   echo '         </ul>';
   echo '         <input type="hidden" name="redirect" value="'.$returnAddress.'">';
   echo '         </fieldset>';
   echo '      </form>';
   echo '   </div>';

}

if ($user->data['is_registered']) {
   echo '<a href="'.$phpbb_root_path.'/ucp.php?mode=logout'.$SID.'">Logout</a>';

}

?>
This works to a point, I no longer get errors YIPPIE! but I'm having trouble reading those blasted sessions and cookies! and the .$returnAddress isn't working either well, time to save up and hope for someone to come help and save me.
Edit: Actually, I just created a topic with a modified version of my script.
Here: http://urltea.com/26x9

Post Reply