• Resolved Malae

    (@malae)


    I am running PHP 5.6.25 have just installed the plugin, but before activating had an error and warnings. I uninstalled the plugin, but would still like to try if they can be corrected. For additional information, I ran debug and found many instances of the following error and warnings:

    [07-Aug-2017 04:54:57 UTC] WordPress database error Specified key was too long; max key length is 1000 bytes for query CREATE TABLE wp_wpcsplog (id mediumint(9) NOT NULL AUTO_INCREMENT, violated_directive varchar(50) NOT NULL default ”,
    blocked_uri varchar(1024) NOT NULL default ”,
    document_uri varchar(1024) NOT NULL default ”,
    useragent varchar(1024) NOT NULL default ”,
    remoteaddress varchar(1024) NOT NULL default ”,
    information text NOT NULL default ”,
    createdon timestamp DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY id (id),
    KEY violated_directive (violated_directive, blocked_uri),
    KEY createdon (createdon)
    ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci made by require_once(‘H:\WAMP64\www\WP-Apsara\wp-admin\admin.php’), require_once(‘H:\WAMP64\www\WP-Apsara\wp-load.php’), require_once(‘H:\WAMP64\www\WP-Apsara\wp-config.php’), require_once(‘H:\WAMP64\www\WP-Apsara\wp-settings.php’), do_action(‘plugins_loaded’), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, wpCSPAdmin::update_database, dbDelta

    [07-Aug-2017 05:16:38 UTC] PHP Warning: array_key_exists() expects parameter 2 to be array, string given in \wp-content\plugins\http-headers\views\cache-control.php on line 47

    PHP Warning: Illegal string offset ‘default’ in \wp-content\plugins\http-headers\views\expires.php on line 74

Viewing 4 replies - 1 through 4 (of 4 total)
  • This is due to key length restriction on MySQL.

    I reduced blocked_uri key length to 256 as follow (line 413 in wpCSPadmin.php) and it works.

    id mediumint(9) NOT NULL AUTO_INCREMENT, violated_directive varchar(50) NOT NULL default ”,
    blocked_uri varchar(256) NOT NULL default ”,
    document_uri varchar(1024) NOT NULL default ”,
    useragent varchar(1024) NOT NULL default ”, remoteaddress varchar(1024) NOT NULL default ”,
    information text ,
    createdon timestamp DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY id (id),
    KEY violated_directive (violated_directive, blocked_uri),
    KEY createdon (createdon)

    • This reply was modified 7 years, 1 month ago by mbikyaw.
    • This reply was modified 7 years, 1 month ago by mbikyaw.
    Plugin Author Dylan

    (@dyland)

    Do you have acces to PhpMyAdmin? Can you try the following:
    ALTER TABLE pptwp_wpcsplog
    ADD KEY violated_directive (violated_directive,blocked_uri(191));

    Might need to delete the key first.

    Plugin Author Dylan

    (@dyland)

    1.7 has the key length fix.

    Thread Starter Malae

    (@malae)

    Hi Dylan,

    Thanks for your belated reply. When I tried your plugin, I was looking for a way to speed up adding CSP on several WP sites. For other sites I usually put the code in the .htaccess file, and make changes there. A plugin seemed an easier way to do this.

    When your plugin produced warnings before even activating, I switched to a different plugin. Regarding the changes to the database, that would have been a last resort and am glad that you followed this suggestion with a fixed version.

    I have just tried the new version 1.8 on a localhost site using PHP 7.1 and it installs and activates with no problems. It appears to be well documented and I will certainly give it a try, when I have some spare time.

    My only comment now is that the default size of the boxes to put the directive arguments could be reduced to a single line and expand as required.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP database error: specified key too long and PHP warnings’ is closed to new replies.