{"id":49,"date":"2014-08-04T18:41:00","date_gmt":"2014-08-04T18:41:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2014\/08\/04\/phpbb-api-logging-in-and-logging-out-a-user\/"},"modified":"2021-02-22T01:02:33","modified_gmt":"2021-02-22T01:02:33","slug":"phpbb-api-logging-in-and-logging-out-a-user","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2014\/08\/phpbb-api-logging-in-and-logging-out-a-user.html","title":{"rendered":"phpBB API &#8211; Logging In And Logging Out a User"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/phpbb.png\"><img decoding=\"async\" title=\"phpbb Logo\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/phpbb.png\" alt=\"phpbb Logo\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">What is PHPBB3<\/h2>\n<p>phpBB is an open source forum software that is very easy to use and build communities. Most importantly it&#8217;s totally free.<\/p>\n<p>phpBB3 provides an API that can be used to automatically login a user from a PHP script.<\/p>\n<p>Although most of the phpBB API functions are documented, however their Wiki lacks examples and can be a little bit difficult to get started.<\/p>\n<p>If you would like to synchronize your website with a phpBB forum, you can use the phpBB sessions to authenticate users.<\/p>\n<h2 style=\"text-align: left;\">Include The Following<\/h2>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">define(&#8216;IN_PHPBB&#8217;, true); \/\/To be allowed to access the API files<br \/>\n$phpbb_root_path = &#8216;..\/phpBB3\/&#8217;; \/\/phpbb forum path<br \/>\n$phpEx = substr(strrchr(__FILE__, &#8216;.&#8217;), 1);<br \/>\nrequire_once($phpbb_root_path . &#8216;common.&#8217; . $phpEx);<br \/>\nrequire_once($phpbb_root_path . &#8216;includes\/functions_display.&#8217; . $phpEx);<\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>Logging in a User<\/h2>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">function phpbbLogin($username, $password)<br \/>\n{<br \/>\nglobal $phpbb_root_path, $phpEx, $user, $auth;<\/span><\/p>\n<p>$user-&gt;session_begin();<br \/>\n$auth-&gt;acl($user-&gt;data);<\/p>\n<p>$auth-&gt;login($username, $password, true);<\/p>\n<p>if($user-&gt;data[&#8216;is_registered&#8217;]==1 &amp;&amp; $user-&gt;data[&#8216;user_type&#8217;] != USER_INACTIVE &amp;&amp; $user-&gt;data[&#8216;user_type&#8217;] != USER_IGNORE)<br \/>\n{<br \/>\necho &#8216;User is logged in&#8217;;<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\"><\/h2>\n<h2 style=\"text-align: left;\">Logging out a User<\/h2>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">function phpbbLogout()<br \/>\n{<br \/>\nglobal $phpbb_root_path, $phpEx, $user;<br \/>\n$user-&gt;session_kill(false);<br \/>\necho &#8216;User is logged out&#8217;;<br \/>\n}<\/span><\/p><\/blockquote>\n<p><b>Questions? Please ask!<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; What is PHPBB3 phpBB is an open source forum software that is very easy to use and build communities. Most importantly it&#8217;s totally free. phpBB3 provides an API that can be used to automatically login a user from a PHP script. Although most of the phpBB API functions are documented, however their Wiki [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[63,22,62],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-api","category-php","category-phpbb3"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}