WordPress Native PHP Sessions

Beschreibung

Der WordPress-Core verwendet keine PHP-Sessions, aber manchmal sind sie für deinen Anwendungsfall, ein Plugin oder ein Theme erforderlich.

Dieses Plugin implementiert die nativen Session-Handler von PHP, die von der WordPress-Datenbank unterstützt werden. Dadurch können Plugins, Themes und benutzerdefinierter Code sicher PHP $_SESSIONs in einer verteilten Umgebung verwenden, in der die standardmäßige Speicherung von temporären PHP-Dateien nicht funktioniert.

Bitte beachte, dass die primäre Entwicklung auf GitHub stattfindet. Wenn du dazu beitragen möchtest:

https://github.com/pantheon-systems/wp-native-php-sessions

Configuration

By default the session lifetime is set to 0, which is until the browser is closed.

To override this use the pantheon_session_expiration filter before the WordPress Native PHP Sessions plugin is loaded. For example a small Must-use plugin (a.k.a. mu-plugin) could contain:

<?php
function my_session_expiration_override() {
    return 60*60*4; // 4 hours
}
add_filter( 'pantheon_session_expiration', 'my_session_expiration_override' );<h3>CLI Commands</h3>

wp pantheon session add-index

Added in 1.4.0. This command should be run if your installation of the plugin occurred before the addition of the primary ID key to the session table in version 1.2.2. You will be automatically notified when you visit any admin page if this is the case. If there’s no message, your version is good to go. Note that this command is non-destructive, a new table will be created and the existing one preserved in a backup state until you have verified that the upgrade is functioning as expected.

wp pantheon session primary-key-finalize

Added in 1.4.0. If you have run the add-index command and have verified that the new table is functioning correctly, running the primary-key-finalize command will perform a database cleanup and remove the backup table.

wp pantheon session primary-key-revert

Added in 1.4.0. If you have run the add-index command and something unexpected has occurred, just run the primary-key-revert command and the backup table will immediately be returned to being the active table.

WordPress Multisite

As of 1.4.2 the add-index, primary-key-add and primary-key-revert commands are fully multisite compatible.

Mitwirken

See CONTRIBUTING.md for information on contributing.

Problembehandlung

Wenn du einen Fehler wie „Fatal error: session_start(): Failed to initialize storage module:“ oder „Warning: ini_set(): A session is active.“ erhältst, dann hast du wahrscheinlich ein Plugin, das eine Session startet, bevor WP Native PHP Sessions geladen wird.

Erstelle eine neue Datei in wp-content/mu-plugins/000-loader.php und füge die folgenden Zeilen ein, um dieses Problem zu beheben:

<?php
require_once WP_PLUGIN_DIR . '/wp-native-php-sessions/pantheon-sessions.php';

Dieses mu-Plugin lädt WP Native PHP Sessions vor allen anderen Plugins, während du weiterhin den WordPress-Plugin-Updater verwenden kannst, um das Plugin auf dem neuesten Stand zu halten.

Installation

  1. Lade das Plugin in das /wp-content/plugins/-Verzeichnis hoch
  2. Aktiviere das Plugin im „Plugins“-Menü in WordPress

Das war’s!

FAQ

Warum kein anderes Session-Plugin verwenden?

Dieses Plugin implementiert die eingebauten PHP-Sitzungsbehandlungsfunktionen, anstatt etwas Benutzerdefiniertes einzuführen. Auf diese Weise kannst du die eingebaute Sprachfunktionen wie $_SESSION superglobal und session_start() in deinem Code verwenden. Alles andere funktioniert dann von alleine.

Warum die Sessions in der Datenbank speichern?

Die Fallback-Standardfunktionalität von PHP besteht darin, dass Sitzungen in einer temporären Datei gespeichert werden können. Das ist es, was der meiste Code, der Sessions aufruft, standardmäßig verwendet, und in einfachen Anwendungsfällen funktioniert, weshalb so viele Plugins dies auch nutzen.

Wenn du beabsichtigst, deine Anwendung zu skalieren, sind lokale temporäre Dateien eine gefährliche Wahl. Sie werden von den verschiedenen Instanzen der Anwendung nicht gemeinsam genutzt, was zu einem erratischen Verhalten führt, dass das Debuggen erschweren kann. Durch ihre Speicherung in der Datenbank wird der Zustand der Sitzungen von allen Anwendungsinstanzen gemeinsam genutzt.

Where do I report security bugs found in this plugin?

Please report security bugs found in the source code of the WP Native PHP Sessions plugin through the Patchstack Vulnerability Disclosure Program. The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.

Rezensionen

8. Januar 2022
I did not have high hopes for this, looking for plugins to resolve the issue my site was having in Site Health and figured I might as well try this after running across it on Google. I installed it, and it fixed loopback requests and API issues in Site Health. I am very impressed!
15. Mai 2021
I have no idea how this plugin even works. As I was going through the list of popular/recommended plugins, this one was way down on the list. I installed it on my test site and it didn't break anything, so I moved it into the production site. I use a plugin that lets me view the error log without having to open an FTP client. Since installing this plugin, I've had almost zero errors in the log. In fact, right now it has been more than 48 hours (pretty high traffic site) and not a single error has been added to the log. Again, I have no clue how this plugin works. I understand the plugin conceptually, else I'd have never installed it. But, the specifics I do not know. What I do know for certain is that there's a marked improvement by way of reduced errors. I think the site may even be more responsive - but it already operates with an A/A on the various page load/speed tests, so I can't measure any difference there. This is a site with more than 70 active plugins and maybe 200 visitors a day.
10. März 2021
Native PHP Sessions is easily another plugin that should be standard for WordPress. And, support is excellent too.
5. August 2020
Native PHP Sessions fixed all errors (curl errors) in my WP installation! Now wordpress shows no errors in the page status but "Top Job" 🙂 Thank you so much!
Alle 16 Rezensionen lesen

Mitwirkende & Entwickler

„WordPress Native PHP Sessions“ ist Open-Source-Software. Folgende Menschen haben an diesem Plugin mitgewirkt:

Mitwirkende

„WordPress Native PHP Sessions“ wurde in 3 Sprachen übersetzt. Danke an die Übersetzerinnen und Übersetzer für ihre Mitwirkung.

Übersetze „WordPress Native PHP Sessions“ in deine Sprache.

Interessiert an der Entwicklung?

Durchstöbere den Code, sieh dir das SVN Repository an oder abonniere das Entwicklungsprotokoll per RSS.

Änderungsprotokoll

1.4.3 (November 13, 2023)

  • Fixed a PHP warning when running the pantheon session add-index command on a single site installation. [#285]

1.4.2 (November 8, 2023)

  • Fixed an issue with the pantheon session add-index PHP warning. [#276]
  • Fixed a syntax issue with the suggested WP CLI commands [#278]
  • Made wp pantheon session add-index, wp pantheon session primary-key-finalize, and wp pantheon session primary-key-revert fully multisite compatible. [#275]

1.4.1 (October 23, 2023)

  • Fixed an issue with the pantheon session add-index command not working properly on WP multisite [#270]
  • Made the notice added in 1.4.0 dismissable (stores in user meta) & hides for multisite (an update is coming to iterate through all sites on a network) [#271]

1.4.0 (October 17, 2023)

  • Adds new CLI command to add a Primary Column (id) to the pantheon_sessions table for users who do not have one. [#265]
  • Adds alert to dashboard for users who need to run the command.
  • 8.3 compatibility and code quality updates
  • Updates Pantheon WP Coding Standards to 2.0 [#264]

1.3.6 (June 1, 2023)

  • Fixes PHP 8.2 deprecated dynamic property error [#251] (props @miguelaxcar)
  • Update CONTRIBUTING.md [#252].
  • Update informational Error message for the case of headers already sent [#249].
  • Add pantheon-wp-coding-standards [#247].

1.3.5 (April 7, 2023)

  • Bump yoast/phpunit-polyfills from 1.0.4 to 1.0.5 [#245].
  • Bump tested up to version

1.3.4 (February 7, 2023)

  • Add fallback for $session->get_data() [[#237(https://github.com/pantheon-systems/wp-native-php-sessions/pull/237)]] (reported on WordPress.org)
  • Update CODEOWNERS file [#239]
  • Fix GPL license in composer.json file [#236]
  • Bump grunt from 1.5.3 to 1.6.1 [#235]

1.3.3 (January 25, 2023)

  • Bump version in pantheon-sessions.php [#234].

1.3.2 (January 25, 2023)

  • PHP 8.2 compatibility [#232].
  • Bump dealerdirect/phpcodesniffer-composer-installer from 0.7.2 to 1.0.0 [#229].
  • Update images for lint and test-behat jobs [#228].

1.3.1 (December 5, 2022)

  • Document session lifetime handling [#224].
  • Make dependabot target develop branch [#226].
  • Ignore .wordpress-org directory [#223].

1.3.0 (November 28th, 2022)

  • Added CONTRIBUTING.MD and GitHub action to automate deployments to wp.org. [#219]

1.2.5 (October 28, 2022)

  • Added #[ReturnTypeWillChange] where required to silence deprecation warnings in PHP 8.1. [#216]

1.2.4 (September 14th, 2021)

  • Die Blob-Größe für neue Session-Tabellen wurde von 64k auf 16M angehoben; Bereits existierende Tabellen benötigen eine manuelle Änderung der Spalte, wenn diese Änderung angewendet werden soll [#193 (engl.)].

1.2.3 (April 9th, 2021)

  • Weist den Tabellennamen einer Variablen zu, bevor er in der Abfrage verwendet wird [#188].

1.2.2 (March 29th, 2021)

  • Enthält eine automatisch inkrementierende id-Spalte zur Unterstützung der Replikation [#187].

1.2.1 (September 17th, 2020)

  • Die Textdomäne des Plugins muss mit dem WordPress.org-Slug identisch sein [#169].

1.2.0 (May 18th, 2020)

  • Vermeidet die Verwendung von Cookies für Sessions, wenn WP-CLI ausgeführt wird [#154].

1.1.0 (April 23rd, 2020)

  • Vermeidet die Initialisierung von PHP-Sessions bei der Ausführung von cron [#149].

1.0.0 (March 2nd, 2020)

  • Das Plugin ist stabil.

0.9.0 (October 14th, 2019)

  • Refaktoriert die Session-Callback-Logik in der Session_Handler-Abstraktion, um den PHP-Hinweis in PHP 7.3 zu beheben [#135].

0.8.1 (August 19th, 2019)

  • Korrigiert die Behandlung des ‚X-Forwarded-For‘-Headers in get_client_ip_server() [#126].

0.8.0 (August 13th, 2019)

  • Respektiert verschiedene HTTP_*-Quellen für die Client-IP-Adresse [#122].

0.7.0 (April 3rd, 2019)

  • Fügt eine Sicherheitsüberprüfung hinzu, die $wpdb wiederherstellt, wenn es fehlt.

0.6.9 (May 15th, 2018)

  • Stellt sicher, dass _pantheon_session_destroy() einen Rückgabewert verwendet.

0.6.8 (May 4th, 2018)

  • Wechselt zu E_USER_WARNING anstelle von E_WARNING, wenn Fehler ausgelöst werden.

0.6.7 (April 26th, 2018)

  • Deaktiviert das Laden des Plugins, wenn WP_INSTALLING gesetzt ist, weil die Erstellung der Sitzungstabelle den Installationsprozess unterbricht.

0.6.6 (March 8th, 2018)

  • Stellt die Sitzungsinstanziierung wieder her, wenn WP-CLI ausgeführt wird, da die Nichtausführung andere Probleme verursacht.

0.6.5 (February 6th, 2018)

  • Deaktiviert die Session-Instanziierung, wenn defined( 'WP_CLI' ) && WP_CLI, weil die Sessions unter CLI nicht funktionieren.

0.6.4 (October 10th, 2017)

  • Löst PHP-Fehler aus, wenn das Plugin die Session nicht in die Datenbank schreiben kann.

0.6.3 (September 29th, 2017)

  • Gibt falsch zurück, wenn es uns völlig misslingt, eine Sitzung zu generieren.

0.6.2 (June 6th, 2017)

  • Synchronisiert die Sitzungsbenutzerkennung, wenn sich ein Benutzer an- und abmeldet.

0.6.1 (May 25th, 2017)

  • Fehlerbehebung: Verhindert Warnung session_write_close() expects exactly 0 parameters, 1 given.

0.6.0 (November 23rd, 2016)

  • Fehlerbehebung: Verhindert einen fatalen PHP-Fehler in session_write_close() beim Ausführen der WordPress-shutdown-Aktion, bevor $wpdb sich selbst zerstört.
  • Fehlerbehebung: Speichert die tatsächliche Benutzer-ID in der Session-Tabelle anstelle von (bool) $user_id.

0.5

  • Kompatibilität mit PHP 7.
  • Fügt pantheon_session_expiration Filter hinzu, um den Ablaufwert der Sitzung zu ändern.

0.4

  • Anpassung am session_id()-Verhalten für größere Kompatibilität
  • Verwendung der superglobal für REQUEST_TIME im Gegensatz zu time()

0.3

  • Behebt ein Problem im Zusammenhang mit der Ladefolge des WordPress-Plugins

0.1

  • Erstveröffentlichung