<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"><channel><title>Disruptive Library Technology Jester &#187; XMLHttpRequest</title> <atom:link href="http://dltj.org/tag/xmlhttprequest/feed/" rel="self" type="application/rss+xml" /><link>http://dltj.org</link> <description>We&#039;re Disrupted, We&#039;re Librarians, and We&#039;re Not Going to Take It Anymore</description> <lastBuildDate>Mon, 06 Feb 2012 20:04:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <cloud domain='dltj.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/us/</creativeCommons:license> <item><title>SSL for WordPress Admin and the Problem with  XMLHttpRequest</title><link>http://dltj.org/article/wordpress-ssl-xmlhttprequest/</link> <comments>http://dltj.org/article/wordpress-ssl-xmlhttprequest/#comments</comments> <pubDate>Thu, 20 Mar 2008 15:38:34 +0000</pubDate> <dc:creator>Peter Murray</dc:creator> <category><![CDATA[Meta Category]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[fix_admin_ssl]]></category> <category><![CDATA[ssl]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[XMLHttpRequest]]></category><guid isPermaLink="false">https://dltj.org/article/wordpress-ssl-xmlhttprequest/</guid> <description><![CDATA[Note! The updates to SSL handling in WordPress version 2.6 handle the problem of SSL-encrypted admin sessions in a much less hackish sort of way. It doesn&#8217;t make any sense to use this plugin with WordPress version 2.6 when you &#8230; <a href="http://dltj.org/article/wordpress-ssl-xmlhttprequest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<abbr class="unapi-id ignore noPrint" title="https://dltj.org/article/wordpress-ssl-xmlhttprequest/"></abbr><div style="border: 2px solid grey; padding: 1.5em;">Note!  The updates to <a href="http://boren.nu/archives/2008/07/14/ssl-and-cookies-in-wordpress-26/" title="&amp;raquo; SSL and Cookies in WordPress 2.6 Ryan Boren">SSL handling in WordPress version 2.6</a> handle the problem of SSL-encrypted admin sessions in a <em>much</em> less hackish sort of way.  It doesn&#8217;t make any sense to use this plugin with <a href="http://wordpress.org/development/2008/07/wordpress-26-tyner/" title="http://wordpress.org/development/2008/07/wordpress-26-tyner/">WordPress version 2.6</a> when you can simply add <code>define(’FORCE_SSL_ADMIN’, true);</code> to your wp-config.php file.</div><p>The WordPress Codex has documentation for <a href="http://codex.wordpress.org/Administration_Over_SSL" title="Administration Over SSL &amp;laquo; WordPress Codex">running the login, registration, and administration interfaces on an SSL server</a>.  There is even a <a href="http://wordpress.org/extend/plugins/admin-ssl-secure-admin/" title="WordPress &#8250; Admin-SSL &laquo; WordPress Plugins">plug-in</a> that will do much of the heavy lifting for you.  I have found both of these methods, by themselves, to be rather unsatisfactory, though, in that admin services that rely on AJAX calls back to WordPress break (such as the periodic saving of drafts).  What happens is this:</p><ol type="1" start="1"><li>Plugins will use the &#8216;siteurl&#8217; and/or &#8216;home&#8217; values in the <a href="http://codex.wordpress.org/General_Options_SubPanel" title="General Options SubPanel &laquo; WordPress Codex">Options &rarr; General</a> admin page, and that value is typically set to the &#8220;http://&#8221; rather than &#8220;https://&#8221; address of the blog.</li><li>The URL that plugins construct to talk back to the WordPress installation will go to an &#8220;http&#8221; address instead of the SSL-encrypted &#8220;https&#8221; address.</li><li>The admin page, loaded in the browser from the &#8220;https&#8221; address, attempts to talk back to the WordPress installation on a &#8220;http&#8221; address and triggers a exception.  In Firefox, the error looks like this: <tt>Error: [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]"...]</tt></li></ol><p>The security model in the browser prevents scripts on a page from using XMLHttpRequest<sup><a href="http://dltj.org/article/wordpress-ssl-xmlhttprequest/#footnote_0_344" id="identifier_0_344" class="footnote-link footnote-identifier-link" title="See http://en.wikipedia.org/wiki/XMLHttpRequest for more information on XMLHttpRequest.">1</a></sup> back to any host on the internet <em>except</em> for the host where the script came from.  In this case, the difference between &#8220;http://&#8230;&#8221; and &#8220;https://&#8230;&#8221; is enough to trigger the problem.</p><p>So I fixed it with plug-in that uses an undocumented hook in WordPress 2.3.  If a plugin requests the value of &#8216;siteurl&#8217; or &#8216;home&#8217;, a filter is called to check if the requested page is on the SSL server.  If it is, the filter changes the URL from &#8216;http&#8217; to &#8216;https&#8217;.  In that way, plug-ins will use the proper form of the URL.</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Fix Admin SSL
Plugin Script: fix_admin_ssl.php
Plugin URI: http://dltj.org/tag/fix_admin_ssl
Description: Fix the 'siteurl' and 'home' option values to make the protocol 'https' rather than 'http' when the page was requested with SSL.
Version: 1.0
License: GPL
Author: Peter Murray
Author URI: http://dltj.org/about
&nbsp;
=== RELEASE NOTES ===
2008-02-18 - v1.0 - first version
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fix_admin_ssl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTPS'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'on'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^http:\/\//'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'https://'</span><span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'option_siteurl'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fix_admin_ssl'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'option_home'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fix_admin_ssl'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>One downside to this plug-in, though, is that it will appear to change the values of &#8216;siteurl&#8217; and &#8216;home&#8217; on the <a href="http://codex.wordpress.org/General_Options_SubPanel" title="General Options SubPanel &laquo; WordPress Codex">Options &rarr; General</a> admin page.  The values in the database are still the &#8216;http&#8217; ones, but since the Options page is an admin page the filter will run when it pre-loads those form fields.</p><p>If there is interest, I can package up the above code into a legitimate plugin and submit it to the <a href="http://wordpress.org/extend/plugins/" title="WordPress &#8250; WordPress Plugins">WordPress plugins list</a>.</p><h2>Footnotes</h2><ol class="footnotes"><li id="footnote_0_344" class="footnote">See <a href="http://en.wikipedia.org/wiki/XMLHttpRequest" title="XMLHttpRequest - Wikipedia">http://en.wikipedia.org/wiki/XMLHttpRequest</a> for more information on XMLHttpRequest.</li></ol>]]></content:encoded> <wfw:commentRss>http://dltj.org/article/wordpress-ssl-xmlhttprequest/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
<!-- Served from: dltj.org @ 2012-02-11 12:31:05 by W3 Total Cache -->
