问题
My theme have a submit post page and I configure user capabilities for everyone to upload.
But no one can able to upload. And when i clicked "add media" button and select any file for upload, my current account is logging out automatically.
Where at, after user try upload, Visitors to the position falls. What do you think? Why logout?
回答1:
Why WordPress Keeps Logging Out?
WordPress sets a cookie in your browser to authenticate a login session. This cookie is set for the WordPress URL stored in your settings section.
If you are accessing from a URL that does not match the one in your WordPress settings, then WordPress will not be able to authenticate your session.
Fixing The Login Issue
A simple fix for this login issue is to make sure that you have the same URL in your Site Address and WordPress Address fields in your WordPress settings.
This means that you need to choose either www or a non-www URL in the both fields.
Login to your WordPress dashboard and go to Settings » General.
If you can’t access the admin area, then you can update these fields by editing the wp-config.php
file.
Connect to your website using an FTP client, and locate the wp-config.php
file in your site’s root directory. You need to download this file to your Desktop and open it in a text editor like Notepad. Add this code just above the line That’s all, stop editing! Happy blogging.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
If you prefer to use www in URL, then use this code instead
define('WP_HOME','http://www.example.com');
define('WP_SITEURL','http://www.example.com');
complete reference
回答2:
This may be helpful to you
To find out what the default (file-based-sessions) session timeout value on the server is you can view it through a ini_get command:
// Get the current Session Timeout Value
$currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’);
Change the Session Timeout Value
// Change the session timeout value to 30 minutes // 8*60*60 = 8 hours
ini_set(’session.gc_maxlifetime’, 30*60);
//————————————————————————————–
// php.ini setting required for session timeout.
ini_set(‘session.gc_maxlifetime’,30);
ini_set(‘session.gc_probability’,1);
ini_set(‘session.gc_divisor’,1);
//————————————————————————————–
//if you want to change the session.cookie_lifetime.
//This required in some common file because to get the session values in whole application we need to write session_start(); to each file then only will get $_SESSION global variable values.
$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime);
session_start();
// Reset the expiration time upon page load //session_name() is default name of session PHPSESSID
if (isset($_COOKIE[session_name()]))
setcookie(session_name(), $_COOKIE[session_name()], time() + $sessionCookieExpireTime, “/”);
//————————————————————————————–
//To get the session cookie set param values.
$CookieInfo = session_get_cookie_params();
echo “<pre>”;
echo “Session information session_get_cookie_params function :: <br />”;
print_r($CookieInfo);
echo “</pre>”;
//————————————————————————————–
Some Description of session related setting for php.ini file.
session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and cleaned up. Garbage collection occurs during session start. session.cookie_lifetime integer
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser.
The value 0 means “until the browser is closed.” Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params().
Since the cookie is returned by the browser, it is not prolonged to suffice the lifetime. It must be sent manually by setcookie().
回答3:
In my case this issue was caused with HTTPS activation and param $secure_cookie of wp_signon function setted as false instead of true/empty
https://developer.wordpress.org/reference/functions/wp_signon/
$creds = [
'user_login' => $user_login,
'user_password' => $password,
'remember' => 'true',
];
$signon = wp_signon($creds, true); // <<< USE true OR REMOVE PARAM
来源:https://stackoverflow.com/questions/37062945/wp-logout-when-upload-on-front