This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

Fixing incorrect cookie settings

Description: This article contains useful information to correct your board's cookie settings.

In Categories:

Link to this article: Select All
[url=https://www.phpbb.com/support/docs/en/3.3/kb/article/fixing-incorrect-cookie-settings/]Knowledge Base - Fixing incorrect cookie settings[/url]

Fixing incorrect cookie settings
Do you keep having problems with staying logged in on your board?
Most likely your Cookie settings are incorrect and this article will help you fix them.

What are our cookie settings?
There are a several methods to change your cookie settings. But of course, before we're going to change the cookie settings we first have to know what our cookie settings are. So here are some examples to give you an idea what your Cookie settings are.


The examples

Example 1:
This is your board URL: http://example.com/phpBB3
Your cookie settings should be:

Cookie domain: .example.com (Note the dot at the beginning!)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.

Example 2:
This is your board URL: http://forums.example.com
Your cookie settings should be:

Cookie domain: forums.example.com (Note that there is no http:// or dot at the beginning and no slash at the end.)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.

Example 3:
This is your board URL: http://example.co.uk
Your cookie settings should be:

Cookie domain: .example.co.uk (Yes, three dots in this scenario because the the tld has 2 and there needs to be one in the front)
Cookie name: cookiename_example (This can be anything what you want, make it original.)
Cookie path: / (Note that this is always a slash, it doesn't matter what your board URL is)
Cookie Secure: Most of the times this is Disabled but when your board is using SSL you have to turn it on, otherwise let it be disabled.

So, I hope this helped you determine what your cookie settings should be. If you have any doubt as to what your Cookie settings should be, feel free to ask this in the Support Forums.

The methods to change
Now you have to edit the settings. That's possible by several methods. We'll explain them here. :)

1. The ACP
phpBB3 has the option to manually change your Cookie settings in the ACP.

First go to the window to edit your settings. :)
You can find it here: ACP ==> Tab "General" ==> Server configuration ==> Cookie settings
Here fill in your new cookie settings you've figured out above. Very simple.

2. A special file
It's also possible that when your cookie settings are incorrect you can't access your board anymore. So we made another solution. A special file that makes it possible to update your cookie settings. This solution is with thanks to ktuk.net and improvements to it have been made courtesy of Oyabun1.

First of all copy the following code and give the file the name cookie.php, upload it in to your forum root where the board's config.php file is as well.

Code: Select all

<?php
/**
*
* @package Cookie and server settings tool
* @copyright (c) 2008 ktuk.net
* @copyright (c) 2011 phpbb.com
* @license GPL
*
*/

// Standard definitions/includes
$page_title = 'phpBB3 Cookies';
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$script_name = (isset($request) && ($request instanceof \phpbb\request\request_interface)) ? $request->server('SCRIPT_NAME', '') : $_SERVER['SCRIPT_NAME'];

$cookie_data = array();
$server_data = array();
$sent = request_var('sent', '');

// Gather cookie settings from config array
$cookie_data[] = $config['cookie_domain'];
$cookie_data[] = $config['cookie_name'];
$cookie_data[] = $config['cookie_path'];
$cookie_data[] = $config['cookie_secure'];

$server_data[] = $config['force_server_vars'];
$server_data[] = $config['script_path'];
$server_data[] = $config['server_name'];
$server_data[] = $config['server_port'];
$server_data[] = $config['server_protocol'];

$cookie_checked = ($cookie_data[3]) ? "checked = \"checked\"" : '';
$force_checked = ($server_data[0]) ? "checked = \"checked\"" : '';


if (!$sent)
{
   print "<html>
   <head><title>$page_title</title></head>
   <body>
   
   <form action=\"" . $script_name . "\" method=\"post\"
   <fieldset>
   <table>
      <tr><h2>Cookie Settings</h2></tr>
      <tr><td>Cookie Domain:</td><td><input type=\"text\" name=\"cookie_domain\" value=\"" . $cookie_data[0] . "\"></td></tr>
      <tr><td>Cookie Name:</td><td><input type=\"text\" name=\"cookie_name\" value=\"" . $cookie_data[1] . "\"></td></tr>
      <tr><td>Cookie Path:</td><td><input type=\"text\" name=\"cookie_path\" value=\"" . $cookie_data[2] . "\"></td></tr>
      <tr><td>Cookie Secure:</td><td><input type=\"checkbox\" name=\"cookie_secure\" value=\"1\" $cookie_checked ></td></tr>
   </table>

   <table>
      <tr><h2>Server Settings</h2></tr>
      <tr><td>Force Server Vars:</td><td><input type=\"checkbox\" name=\"force_server_vars\" value=\"1\"  $force_checked ></td></tr>
      <tr><td>Script Path:</td><td><input type=\"text\" name=\"script_path\" value=\"" . $server_data[1] . "\"></td></tr>
      <tr><td>Server Name:</td><td><input type=\"text\" name=\"server_name\" value=\"" . $server_data[2] . "\"></td></tr>
      <tr><td>Server Port:</td><td><input type=\"text\" name=\"server_port\" value=\"" . $server_data[3] . "\"></td></tr>
      <tr><td>Server Protocol:</td><td><input type=\"text\" name=\"server_protocol\" value=\"" . $server_data[4] . "\"></td></tr>
      <tr><td>Submit:</td><td><input type=\"submit\" name=\"sent\" value=\"submit\"></td></tr>
   </table>
   </fieldset>
   </body>
   <html>
   ";
}

if ($sent)
{
   $cookie_domain      = request_var('cookie_domain', '');
   $cookie_name      = request_var('cookie_name', '');
   $cookie_path      = request_var('cookie_path', '');
   $cookie_secure      = request_var('cookie_secure', 0);
   $force_server_vars   = request_var('force_server_vars', 0);
   $script_path      = request_var('script_path', '');
   $server_name      = request_var('server_name', '');
   $server_port      = request_var('server_port', 80);
   $server_protocol   = request_var('server_protocol', 'http://');

   $sql_ary = array(
       'cookie_domain'      => $cookie_domain,
       'cookie_name'      => $cookie_name,
       'cookie_path'      => $cookie_path,
       'cookie_secure'      => $cookie_secure,
       'force_server_vars'   => $force_server_vars,
       'script_path'      => $script_path,
       'server_name'      => $server_name,
       'server_port'      => $server_port,
       'server_protocol'   => $server_protocol
   );

   foreach ($sql_ary as $config_name => $config_value)
   {
      set_config($config_name, $config_value);
   }

   print "Settings are updated!";
   print "<meta http-equiv=\"refresh\" content=\"4;./cookie.php\">";
}
Browse to the script at its URL in your web browser, for example http://www.example.com/forum/cookie.php The script will then load a form showing your current server and cookie details which you can amend to the correct settings. Once you have got the settings edited correctly, click the submit button. After you're finished don't forgot to remove the script from your server. Otherwise everyone can edit your settings.

3. The database
Another possibility is using the database to run a few queries that update your cookie settings. Go to phpMyAdmin and run the following queries:

Code: Select all

UPDATE phpbb_config SET config_value = 'YOUR COOKIE DOMAIN HERE' WHERE config_name = 'cookie_domain';
UPDATE phpbb_config SET config_value = 'YOUR COOKIE NAME HERE' WHERE config_name = 'cookie_name';
UPDATE phpbb_config SET config_value = 'YOUR COOKIE PATH HERE' WHERE config_name = 'cookie_path';
UPDATE phpbb_config SET config_value = '0' WHERE config_name = 'cookie_secure';
Please note that you have to replace the first 3 with your settings and for the last one you only edit the zero when you have Cookie Secure enabled, otherwise you don't do anything with it. Also note that when your table prefix is not phpbb_ you have to edit it to your database table prefix, and don't forget to purge the cache by removing all files from the cache folder except index.htm and .htaccess. :)

So, I hope your cookie settings are correct now and you can enjoy the "Log me on automatically each visit" option!

Updates:
08-02-2010 JimA - Added Example 3
07/12/2011 stevemaury - Removed backticks from SQL and made some grammatical corrections. Also changed "index.html" to index.htm".
7Dec2011 D¡cky - Removed SQL queries from cookie.php and replaced with functions
21-July-2016 JimA - Updated to suit both 3.0.x, 3.1.x and 3.2.x