Topic: Log on form the website
I would like to make a log on form on my website, how to do it?
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Log on form the website
I would like to make a log on form on my website, how to do it?
*lol*
I had this same issue, and it was so easy.
I just looked at the source of the login screen and copy/pasted. Then styled to fit my page.
Simple and effective!
I can't find it in login.php can you post the correct form code?
And how can I check if the user is logged in and what are his rights (is he a moderator or not)?
Website Integration
Integrating PunBB into your website code is easy if you know a little PHP. By including PunBB's script common.php, you gain access to all PunBB global variables such as $db and $pun_user. However, in order to include this file, you need to define a constant called PUN_ROOT. This constant should be set to the relative path to your PunBB forum directory. For example, if your website front page is located in /home/user/public_html/ and your forums are located in /home/user/public_html/forums/, your PUN_ROOT should be './forums/'. The PHP code to accomplish this could look something like this:
define('PUN_ROOT', './forums/');
require PUN_ROOT.'include/common.php';Once you've included common.php, you can access and utilize all of PunBB's global variables and functions. Typically, you will be most interested in the $pun_user array. This array holds information about the current user. Another interesting variable is the database object $db. How to use these variables in your own script is out of the scope of this document, but here's a small example showing you how to print a simple message greeting the current user on your website front page:
Hello <?php echo pun_htmlspecialchars($pun_user['username']); ?>!
In addition to defining PUN_ROOT, you can define a number of other constants to alter the behaviour of PunBB when including common.php. The two most interesting of these constants are PUN_TURN_OFF_MAINT and PUN_QUIET_VISIT. If PUN_TURN_OFF_MAINT is defined when including common.php, PunBB will not exit and display the maintenance message if the forums are placed into maintenance mode. You generally don't want this message to appear on your website front page, so defining that constant is a good idea. The other constant, PUN_QUIET_VISIT, prevents PunBB from updating the current user's last visit data in the database so that a visit to the front page doesn't count as a visit in the forums. This is also desirable behaviour in most cases. It doesn't matter what value you set these constants to, but setting them to a value of 1 is probably a good idea. Example:
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);Please note that these constants must be defined before common.php is included.
ConnorHD - I had to much trouble with that, so I just used HTML.
macius - Put this in the header right before "</head>"...It's the Javascript that prevents them from logging in without putting in a username or password.
<script type="text/javascript">
<!--
function process_form(the_form)
{
var element_names = new Object()
element_names["req_username"] = "Username"
element_names["req_password"] = "Password"
if (document.all || document.getElementById)
{
for (i = 0; i < the_form.length; ++i)
{
var elem = the_form.elements[i]
if (elem.name && elem.name.substring(0, 4) == "req_")
{
if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
{
alert("\"" + element_names[elem.name] + "\" is a required field in this form.")
elem.focus()
return false
}
}
}
}
return true
}
// -->
</script>
This is the login info...(I modded it for my site, mod it to match your own...)
<form id="login" method="post" action="forumroot/login.php?action=in" onsubmit="return process_form(this)">
<div class="infldset">
<input type="hidden" name="form_sent" value="1" /> <input type="hidden" name="redirect_url" value="index.php" />
<label class="conl"><strong>Username</strong>
<br />
<input type="text" name="req_username" size="10" maxlength="25" tabindex="1" />
<br /></label>
<label class="conl"><strong>Password</strong>
<br />
<input type="password" name="req_password" size="10" maxlength="16" tabindex="2" /><br /></label>
<a href="forumroot/register.php" tabindex="4">Not registered yet?</a><br />
<a href="forumroot/login.php?action=forget" tabindex="5">Forgotten your password?</a>
<br />
<input type="submit" name="login" value="Login" tabindex="3" />
</div>
</form>
Change all instances of "forumroot" to the path of your forum.
erissiva: i think you need php to stop people from viewing a page while logged out
heres an example
<?php
define('PUN_ROOT', './forums/');
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
if ($pun_user['is_guest'])
exit('Sorry you must login to view this page');
?>
HTML SITE
erissiva: i think you need php to stop people from viewing a page while logged out
heres an example
<?php define('PUN_ROOT', './forums/'); define('PUN_TURN_OFF_MAINT', 1); define('PUN_QUIET_VISIT', 1); require PUN_ROOT.'include/common.php'; if ($pun_user['is_guest']) exit('Sorry you must login to view this page'); ?> HTML SITE
Oh, well I was just going for a basic login-redirect issue. All the pages on the rest of the site are done through punBB, so I don't have to worry about that. I don't want people to have to register to see the index of my site.
Edit: Oh, wait. I didn't see maicus' post about checking user rights. *ka-doh!* Sorry...
Ignore me!
if ($pun_user['is_guest']) ?>
And how to check if he user is a moderator and admin?
$pun_user['group_id']
1 is admin 2 is mod 3 is guest 4 is member 5+ are other groups i think
Like this?
if ($pun_user['1'])
no
if ($pun_user['group_id'] == 1)
i think
1 can be replaced with PUN_ADMIN
2 with PUN_MOD
Thanks, it works.
DO you know how to redirect to my home page after logging out.
line 100 login.php
redirect('index.php', $lang_login['Logout redirect']);
put the url where it says index.php
I want to create a logging out link.
<a href="forum/login.php?action=out&id=2">Log out</a>
Maybe there is a way to do something like here
<input type="hidden" name="redirect_url" value="index.php" />
Edit: I have just noticed that id is different for each user, is there other way to do that?
<?php echo $pun_user['id'] ?> will insert the id anywhere in the page
I use this code (lines 59 an 60)
if ($pun_user['group_id'] == PUN_ADMIN||$pun_user['group_id'] == PUN_MOD)
echo("<a href=\"forum/login.php?action=out&id=$pun_user['id']\">LOG OUT</a>");
And it doesn't work:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\usr\krasnal\www\_jgames_\index.php on line 60
Why?
if ($pun_user['group_id'] == PUN_ADMIN || $pun_user['group_id'] == PUN_MOD)
echo("<a href=\"forum/login.php?action=out&id=$pun_user['id']\">LOG OUT</a>");
might work better
No, still the same.
That's the whole code:
<html>
<head>
<?php
define('PUN_ROOT', './forum/');
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
?>
<script type="text/javascript">
<!--
function process_form(the_form)
{
var element_names = new Object()
element_names["req_username"] = "Username"
element_names["req_password"] = "Password"
if (document.all || document.getElementById)
{
for (i = 0; i < the_form.length; ++i)
{
var elem = the_form.elements[i]
if (elem.name && elem.name.substring(0, 4) == "req_")
{
if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
{
alert("\"" + element_names[elem.name] + "\" jest wymagane aby si? zalogowa?.")
elem.focus()
return false
}
}
}
}
return true
}
// -->
</script>
</head>
<body>
<?php
if ($pun_user['is_guest'])
{
echo('<form id="login" method="post" action="forum/login.php?action=in" onsubmit="return process_form(this)">
<div class="infldset">
<input type="hidden" name="form_sent" value="1" />
<input type="hidden" name="redirect_url" value="../index.php" />
<logowanie>Login: </logowanie>
<input type="text" name="req_username" size="10" maxlength="25" tabindex="1" />
<logowanie> Has?o: </logowanie>
<input type="password" name="req_password" size="10" maxlength="16" tabindex="2" />
<input type="submit" name="login" value="Login" tabindex="3" />
</form>');
}
if ($pun_user['group_id'] == PUN_ADMIN || $pun_user['group_id'] == PUN_MOD)
echo("<a href=\"forum/login.php?action=out&id=$pun_user['id']\">LOG OUT</a>");
/*dla reszty*/
else
{
}
?>
</body>
</html>
if ($pun_user['group_id'] == PUN_ADMIN || $pun_user['group_id'] == PUN_MOD)
echo("<a href=\"forum/login.php?action=out&id=".$pun_user['id']."\">LOG OUT</a>");
?
Yeah it works, thanks for help.
There is another problem. Although I am logged in all the time, I'm not logged in till I open the forum site.
I enabled "Save username and password between visits." option. And I have to visit the forum first to make this code work:
if ($pun_user['group_id'] == PUN_ADMIN || $pun_user['group_id'] == PUN_MOD)
echo("<a href=\"forum/login.php?action=out&id=".$pun_user['id']."\">LOG OUT</a>");
please help me, i have a probleme when i logged me with the login script. the user has'nt updated on table ("forum_online" for me) what is the solution ??
<?php
define('PUN_ROOT', './forum/');
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
if ($pun_user['group_id'] == PUN_ADMIN || $pun_user['group_id'] == PUN_MOD || $pun_user['group_id'] == PUN_MEMBER)
echo $pun_user['username']." <a href=\"forum/login.php?action=out&id=".$pun_user['id']."\">LOG OUT</a>";
else {
?>
<script type="text/javascript">
<!--
function process_form(the_form)
{
var element_names = new Object()
element_names["req_username"] = "Username"
element_names["req_password"] = "Password"
if (document.all || document.getElementById)
{
for (i = 0; i < the_form.length; ++i)
{
var elem = the_form.elements[i]
if (elem.name && elem.name.substring(0, 4) == "req_")
{
if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
{
alert("\"" + element_names[elem.name] + "\" is a required field in this form.")
elem.focus()
return false
}
}
}
}
}
-->
</script>
<form id="login" method="post" action="forum/login.php?action=in" onsubmit="return process_form(this)">
<div class="infldset">
<input type="hidden" name="form_sent" value="1" /> <input type="hidden" name="redirect_url" value="index.php" />
<label class="conl"><strong>Username</strong>
<br />
<input type="text" name="req_username" size="10" maxlength="25" tabindex="1" />
<br /></label>
<label class="conl"><strong>Password</strong>
<br />
<input type="password" name="req_password" size="10" maxlength="16" tabindex="2" /><br /></label>
<a href="forum/register.php" tabindex="4">Not registered yet?</a><br />
<a href="forum/login.php?action=forget" tabindex="5">Forgotten your password?</a>
<br />
<input type="submit" name="login" value="Login" tabindex="3" />
</div>
</form>
<?php
}
?>
<br><br>
Liste des connecté(es)<br>
<?php
if ($pun_config['o_users_online'] == '1')
{
// Fetch users online info and generate strings for output
$num_guests = 0;
$users = array();
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
while ($pun_user_online = $db->fetch_assoc($result))
{
if ($pun_user_online['user_id'] > 1)
$users[] = "<a href=\"forum/profile.php?id=".$pun_user_online['user_id']."\">".pun_htmlspecialchars($pun_user_online['ident'])."</a>";
else
++$num_guests;
}
$num_users = count($users);
if ($num_users > 0)
echo implode(' - ', $users);
}
?>
Thanks you to reply me
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Log on form the website
Powered by PunBB, supported by Informer Technologies, Inc.