phpBB

Development Wiki

Difference between revisions of "Function.login box"

From phpBB Development Wiki

m (Experimenting with additional table columns for the parameters of a function.)
m
 
(6 intermediate revisions by 5 users not shown)
Line 2: Line 2:
  
 
==Description==
 
==Description==
#<code>void '''login_box''' ( [ $redirect [, $l_explain [, $l_success [, $admin [, $s_display ]]]]] )</code>
+
#<pre>void login_box ( [ $redirect [, $l_explain [, $l_success [, $admin [, $s_display ]]]]] )</pre>
 
The login_box() function can have a redirect as the first parameter. As a rule of thumb, specify an empty string if you want to redirect to the users current location, otherwise do not add the $SID ([[append_sid]]) to the redirect string (for example within the ucp/login we redirect to the board index, otherwise the user would be redirected back to the login screen -- perpetually).
 
The login_box() function can have a redirect as the first parameter. As a rule of thumb, specify an empty string if you want to redirect to the users current location, otherwise do not add the $SID ([[append_sid]]) to the redirect string (for example within the ucp/login we redirect to the board index, otherwise the user would be redirected back to the login screen -- perpetually).
  
Line 20: Line 20:
 
| No
 
| No
 
| <nowiki>''</nowiki>
 
| <nowiki>''</nowiki>
| (optional) Language string to use for the Login Message. Defaults to  
+
| Language string to use for the Login Message. Defaults to  
 
|-
 
|-
 
| '''l_success'''
 
| '''l_success'''
 
| No
 
| No
 
| <nowiki>''</nowiki>
 
| <nowiki>''</nowiki>
| (optional) Language string to use for the Login Successful Message.
+
| Language string to use for the Login Successful Message.
 
|-
 
|-
 
| '''admin'''
 
| '''admin'''
 
| No
 
| No
 
| false
 
| false
| (optional) Used for second-login for Administrators. The ACP utilises this parameter.
+
| Used for second-login for Administrators. The ACP utilises this parameter.
 
|-
 
|-
 
| '''s_display'''
 
| '''s_display'''
 
| No
 
| No
 
| true
 
| true
| (optional) Display forgot password and resend activation links, autologin and hide session checkboxes.
+
| Display forgot password and resend activation links, autologin and hide session checkboxes.
 
|}<br>
 
|}<br>
  
Line 43: Line 43:
 
==Examples==
 
==Examples==
 
===Example #1 Show the login box if user is not logged in===
 
===Example #1 Show the login box if user is not logged in===
<php>if (!$user->data['user_type'] == ANONYMOUS)
+
<php>if ($user->data['user_id'] == ANONYMOUS)
 
{
 
{
 
     login_box('', $user->lang['LOGIN']);
 
     login_box('', $user->lang['LOGIN']);
Line 71: Line 71:
  
 
==Notes==
 
==Notes==
===Tip===
+
===Leaving $redirect empty===
Leaving $redirect empty will cause redirection to the original page; in fact the login_box function can be called without any parameters.<br>
+
: <div class="toc" style="padding:10px;">Leaving $redirect empty will cause redirection to the original page; in fact the login_box function can be called without any parameters.</div>
 +
<br>
  
 
==See Also==
 
==See Also==
Line 81: Line 82:
 
[[Category:API]]
 
[[Category:API]]
 
[[Category:Sessions]]
 
[[Category:Sessions]]
 +
[[Category:Functions]]
 +
 +
[[ja:Function.login_box]]

Latest revision as of 05:33, 15 March 2010

login_box –– Generate login box or verify password

Description

  1. void login_box ( [ $redirect [, $l_explain [, $l_success [, $admin [, $s_display ]]]]] )

The login_box() function can have a redirect as the first parameter. As a rule of thumb, specify an empty string if you want to redirect to the users current location, otherwise do not add the $SID (append_sid) to the redirect string (for example within the ucp/login we redirect to the board index, otherwise the user would be redirected back to the login screen -- perpetually).

Parameters

Parameter Required Default Usage
redirect No '' URL location the script will redirect to once the user is successfully logged in. Defaults to the current page.
l_explain No '' Language string to use for the Login Message. Defaults to
l_success No '' Language string to use for the Login Successful Message.
admin No false Used for second-login for Administrators. The ACP utilises this parameter.
s_display No true Display forgot password and resend activation links, autologin and hide session checkboxes.

Return Values

This function returns NULL if the user is banned

Examples

Example #1 Show the login box if user is not logged in

if ($user->data['user_id'] == ANONYMOUS)
{
    
login_box(''$user->lang['LOGIN']);
}

Example #2 Show the login box with redirect

Verify the user has searching permissions, if they do not, and the user is not logged in, we show a login box. If the user is logged in, we throw a "not allowed to access this page" error.

// Start auth check
if (!$auth->acl_get('u_search'))
{
    
// the user is logged in, therefore we give an error message
    
if ($user->data['user_id'] != ANONYMOUS)
    {
        
trigger_error('NOT_AUTHORISED');
    }

    
// the user is not logged in, we show a login box with a message
    
login_box($phpbb_root_path 'my_page.' $phpEx$user->lang['LOGIN_VIEWPAGE']);
}

Example #3 Re-Authentication Login for Administrators

Display a login box if the logged-in administrator has not authenticated a second time for the admin session.

if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
{
    
login_box(''$user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], truefalse);
}

Notes

Leaving $redirect empty

Leaving $redirect empty will cause redirection to the original page; in fact the login_box function can be called without any parameters.


See Also