<?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/"
	>

<channel>
	<title>AskApache &#187; PHP</title>
	<atom:link href="http://www.askapache.com/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Fri, 25 Jun 2010 00:55:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Session File Hacks</title>
		<link>http://www.askapache.com/php/php-session-hack.html</link>
		<comments>http://www.askapache.com/php/php-session-hack.html#comments</comments>
		<pubDate>Fri, 25 Jun 2010 00:00:09 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WiredTree]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Sessions]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[umask]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1019</guid>
		<description><![CDATA[<p><strong>What they say about kung-fu is true</strong>..</p>
<p>It can be attained by anyone through <em>hard work over time</em>.   You can become as good as the amount of work you put in.   Here's a short look at a basic technique that I use.  Simply reverse engineering the source code and taking notes along the way...</p>
<pre>static void php_session_send_cookie(TSRMLS_D)
  if (SG(headers_sent)) {
          if (output_start_filename) {
                  php_error_docref(NULL TSRMLS_CC, E_WARNING, &#34;Cannot send session cookie - headers already sent by (output started at %s:%d)&#34;,
                          output_start_filename, output_start_lineno);
          } else {
                  php_error_docref(NULL TSRMLS_CC, E_WARNING, &#34;Cannot send session cookie - headers already sent&#34;);
          }
          return;
  }
&#160;
  /* URL encode session_name and id because they might be user supplied */
  e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name)), NULL);</pre>]]></description>
			<content:encoded><![CDATA[<p>If you want to learn best tricks and tips, there&#8217;s only one way to do it&#8230; at least only one way that I know of.  Here are some notes I created while learning about the intricacies of php sessions, it&#8217;s all in the code.</p>
<pre>[Session]
; Handler used to store/retrieve data.
session.save_handler = files</pre>
<p>Argument passed to save_handler.  In the case of files, this is the path where data files are stored. As of PHP 4.0.1, you can define the path as:</p>
<pre>session.save_path = &quot;N;/path&quot;</pre>
<p> where N is an integer.  Instead of storing all the session files in<br />
 /path, what this will do is use subdirectories N-levels deep, and<br />
 store the session data in those directories.  This is useful if you<br />
 or your OS have problems with lots of files in one directory, and is<br />
 a more efficient layout for servers that handle lots of sessions.</p>
<pre>;
; NOTE 1: PHP will not create this directory structure automatically.
;         You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
;         use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
;     session.save_path = &quot;N;MODE;/path&quot;
;
; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process&#039;s umask.
;session.save_path = &quot;/tmp&quot;</pre>
<h3>session.c</h3>
<pre>/* {{{ PHP_INI
 */
PHP_INI_BEGIN()
        STD_PHP_INI_BOOLEAN(&quot;session.bug_compat_42&quot;,    &quot;1&quot;,         PHP_INI_ALL, OnUpdateBool,   bug_compat,         php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN(&quot;session.bug_compat_warn&quot;,  &quot;1&quot;,         PHP_INI_ALL, OnUpdateBool,   bug_compat_warn,    php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.save_path&quot;,          &quot;&quot;,          PHP_INI_ALL, OnUpdateSaveDir,save_path,          php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.name&quot;,               &quot;PHPSESSID&quot;, PHP_INI_ALL, OnUpdateString, session_name,       php_ps_globals,    ps_globals)
        PHP_INI_ENTRY(&quot;session.save_handler&quot;,           &quot;files&quot;,     PHP_INI_ALL, OnUpdateSaveHandler)
        STD_PHP_INI_BOOLEAN(&quot;session.auto_start&quot;,       &quot;0&quot;,         PHP_INI_ALL, OnUpdateBool,   auto_start,         php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.gc_probability&quot;,     &quot;1&quot;,         PHP_INI_ALL, OnUpdateLong,    gc_probability,     php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.gc_divisor&quot;,         &quot;100&quot;,       PHP_INI_ALL, OnUpdateLong,    gc_divisor,        php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.gc_maxlifetime&quot;,     &quot;1440&quot;,      PHP_INI_ALL, OnUpdateLong,    gc_maxlifetime,     php_ps_globals,    ps_globals)
        PHP_INI_ENTRY(&quot;session.serialize_handler&quot;,      &quot;php&quot;,       PHP_INI_ALL, OnUpdateSerializer)
        STD_PHP_INI_ENTRY(&quot;session.cookie_lifetime&quot;,    &quot;0&quot;,         PHP_INI_ALL, OnUpdateLong,    cookie_lifetime,    php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.cookie_path&quot;,        &quot;/&quot;,         PHP_INI_ALL, OnUpdateString, cookie_path,        php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.cookie_domain&quot;,      &quot;&quot;,          PHP_INI_ALL, OnUpdateString, cookie_domain,      php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN(&quot;session.cookie_secure&quot;,    &quot;&quot;,          PHP_INI_ALL, OnUpdateBool,   cookie_secure,      php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN(&quot;session.cookie_httponly&quot;,  &quot;&quot;,          PHP_INI_ALL, OnUpdateBool,   cookie_httponly,    php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN(&quot;session.use_cookies&quot;,      &quot;1&quot;,         PHP_INI_ALL, OnUpdateBool,   use_cookies,        php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN(&quot;session.use_only_cookies&quot;, &quot;0&quot;,         PHP_INI_ALL, OnUpdateBool,   use_only_cookies,   php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.referer_check&quot;,      &quot;&quot;,          PHP_INI_ALL, OnUpdateString, extern_referer_chk, php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.entropy_file&quot;,       &quot;&quot;,          PHP_INI_ALL, OnUpdateString, entropy_file,       php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.entropy_length&quot;,     &quot;0&quot;,         PHP_INI_ALL, OnUpdateLong,    entropy_length,     php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.cache_limiter&quot;,      &quot;nocache&quot;,   PHP_INI_ALL, OnUpdateString, cache_limiter,      php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.cache_expire&quot;,       &quot;180&quot;,       PHP_INI_ALL, OnUpdateLong,    cache_expire,       php_ps_globals,    ps_globals)
        PHP_INI_ENTRY(&quot;session.use_trans_sid&quot;,          &quot;0&quot;,         PHP_INI_ALL, OnUpdateTransSid)
        STD_PHP_INI_ENTRY(&quot;session.hash_function&quot;,      &quot;0&quot;,         PHP_INI_ALL, OnUpdateLong,    hash_func,          php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY(&quot;session.hash_bits_per_character&quot;,      &quot;4&quot;,         PHP_INI_ALL, OnUpdateLong,    hash_bits_per_character,          php_ps_globals,    ps_globals)
&nbsp;
        /* Commented out until future discussion */
        /* PHP_INI_ENTRY(&quot;session.encode_sources&quot;, &quot;globals,track&quot;, PHP_INI_ALL, NULL) */
PHP_INI_END()
/* }}} */</pre>
<h3>Session Errors</h3>
<pre>The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and &#039;-,&#039;
fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)
open(%s, O_RDWR) failed: %s (%d)
ps_files_cleanup_dir: opendir(%s) failed: %s (%d)
read failed: %s (%d)
read returned less bytes than requested
write failed: %s (%d)
write wrote less bytes than requested
mm_malloc failed, avail %d, err %s
cannot allocate new data segment
Skipping numeric key %ld.
A session is active. You cannot change the session module&#039;s ini settings at this time.
Cannot find save handler %s
Cannot find serialization handler %s
Unknown session.serialize_handler. Failed to encode session object.
Cannot encode non-existent session.
Unknown session.serialize_handler. Failed to decode session object.
Failed to decode session object. Session has been destroyed.
Invalid session hash function
The ini setting hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now
No storage module chosen - failed to initialize session.
Failed to initialize storage module: %s (path: %s)
The session bug compatibility code will not
Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively.
Failed to write session data (%s). Please
Cannot send session cache limiter - headers already sent (output started at %s:%d)
Cannot send session cache limiter - headers already sent
Cannot send session cookie - headers already sent by (output started at %s:%d)
Cannot send session cookie - headers already sent
Cannot find save handler %s
Cannot find unknown save handler
purged %d expired session objects
Trying to destroy uninitialized session
Session object destruction failed
Cannot find named PHP session module (%s)
Argument %d is not a valid callback
Cannot regenerate session id - headers already sent
Session object destruction failed</pre>
<pre>PS_GC_FUNC(files)
{
        PS_FILES_DATA;
&nbsp;
        /* we don&#039;t perform any cleanup, if dirdepth is larger than 0.
           we return SUCCESS, since all cleanup should be handled by
           an external entity (i.e. find -ctime x | xargs rm) */
&nbsp;
        if (data-&gt;dirdepth == 0) {
                *nrdels = ps_files_cleanup_dir(data-&gt;basedir, maxlifetime TSRMLS_CC);
        }
&nbsp;
        return SUCCESS;
}</pre>
<h3>mod_files.c</h3>
<pre>/* If you change the logic here, please also update the error message in
 * ps_files_open() appropriately */
static int ps_files_valid_key(const char *key)
{
        size_t len;
        const char *p;
        char c;
        int ret = 1;
&nbsp;
        for (p = key; (c = *p); p++) {
                /* valid characters are a..z,A..Z,0..9 */
                if (!((c &gt;= &#039;a&#039; &amp;&amp; c &lt;= &#039;z&#039;)
                                || (c &gt;= &#039;A&#039; &amp;&amp; c &lt;= &#039;Z&#039;)
                                || (c &gt;= &#039;0&#039; &amp;&amp; c &lt;= &#039;9&#039;)
                                || c == &#039;,&#039;
                                || c == &#039;-&#039;)) {
                        ret = 0;
                        break;
                }
        }
&nbsp;
        len = p - key;
&nbsp;
        if (len == 0) {
                ret = 0;
        }
&nbsp;
        return ret;
}</pre>
<pre>static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
{
        DIR *dir;
        char dentry[sizeof(struct dirent) + MAXPATHLEN];
        struct dirent *entry = (struct dirent *) &amp;dentry;
        struct stat sbuf;
        char buf[MAXPATHLEN];
        time_t now;
        int nrdels = 0;
        size_t dirname_len;
&nbsp;
        dir = opendir(dirname);
        if (!dir) {
                php_error_docref(NULL TSRMLS_CC, E_NOTICE, &quot;ps_files_cleanup_dir: opendir(%s) failed: %s (%d)&quot;, dirname, strerror(errno), errno);
                return (0);
        }
&nbsp;
        time(&amp;now);
&nbsp;
        dirname_len = strlen(dirname);
&nbsp;
        /* Prepare buffer (dirname never changes) */
        memcpy(buf, dirname, dirname_len);
        buf[dirname_len] = PHP_DIR_SEPARATOR;
&nbsp;
        while (php_readdir_r(dir, (struct dirent *) dentry, &amp;entry) == 0 &amp;&amp; entry) {
                /* does the file start with our prefix? */
                if (!strncmp(entry-&gt;d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1)) {
                        size_t entry_len = strlen(entry-&gt;d_name);
&nbsp;
                        /* does it fit into our buffer? */
                        if (entry_len + dirname_len + 2 &lt; MAXPATHLEN) {
                                /* create the full path.. */
                                memcpy(buf + dirname_len + 1, entry-&gt;d_name, entry_len);
&nbsp;
                                /* NUL terminate it and */
                                buf[dirname_len + entry_len + 1] = &#039;\0&#039;;
&nbsp;
                                /* check whether its last access was more than maxlifet ago */
                                if (VCWD_STAT(buf, &amp;sbuf) == 0 &amp;&amp;
#ifdef NETWARE
                                                (now - sbuf.st_mtime.tv_sec) &gt; maxlifetime) {
#else
                                                (now - sbuf.st_mtime) &gt; maxlifetime) {
#endif
                                        VCWD_UNLINK(buf);
                                        nrdels++;
                                }
                        }
                }
        }
&nbsp;
        closedir(dir);
&nbsp;
        return (nrdels);
}</pre>
<h3>ext/session/mod_files.c</h3>
<pre>#define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
&nbsp;
PS_OPEN_FUNC(files)
{
        ps_files *data;
        const char *p, *last;
        const char *argv[3];
        int argc = 0;
        size_t dirdepth = 0;
        int filemode = 0600;
&nbsp;
        if (*save_path == &#039;\0&#039;) {
                /* if save path is an empty string, determine the temporary dir */
                save_path = php_get_temporary_directory();
&nbsp;
                if (strcmp(save_path, &quot;/tmp&quot;)) {
                        if (PG(safe_mode) &amp;&amp; (!php_checkuid(save_path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
                                return FAILURE;
                        }
                        if (php_check_open_basedir(save_path TSRMLS_CC)) {
                                return FAILURE;
                        }
                }
        }
&nbsp;
        /* split up input parameter */
        last = save_path;
        p = strchr(save_path, &#039;;&#039;);
        while (p) {
                argv[argc++] = last;
                last = ++p;
                p = strchr(p, &#039;;&#039;);
                if (argc &gt; 2) break;
        }
        argv[argc++] = last;
&nbsp;
        if (argc &gt; 1) {
                errno = 0;
                dirdepth = (size_t) strtol(argv[0], NULL, 10);
                if (errno == ERANGE) {
                        php_error(E_WARNING, &quot;The first parameter in session.save_path is invalid&quot;);
                        return FAILURE;
                }
        }
&nbsp;
        if (argc &gt; 2) {
                errno = 0;
                filemode = strtol(argv[1], NULL, 8);
                if (errno == ERANGE || filemode &lt; 0 || filemode &gt; 07777) {
                        php_error(E_WARNING, &quot;The second parameter in session.save_path is invalid&quot;);
                        return FAILURE;
                }
        }
        save_path = argv[argc - 1];
&nbsp;
        data = emalloc(sizeof(*data));
        memset(data, 0, sizeof(*data));
&nbsp;
        data-&gt;fd = -1;
        data-&gt;dirdepth = dirdepth;
        data-&gt;filemode = filemode;
        data-&gt;basedir_len = strlen(save_path);
        data-&gt;basedir = estrndup(save_path, data-&gt;basedir_len);
&nbsp;
        PS_SET_MOD_DATA(data);
&nbsp;
        return SUCCESS;
}</pre>
<blockquote><pre>[PHP 5.2.0 session.save_path safe_mode and open_basedir bypass]
&nbsp;
Author: Maksymilian Arciemowicz (SecurityReason)
Date:
- - Written: 02.10.2006
- - Public: 08.12.2006
SecurityAlert Id: 43
CVE: CVE-2006-6383
SecurityRisk: High
Affected Software: PHP 5.2.0
Advisory URL: http://securityreason.com/achievement_securityalert/43
Vendor: http://www.php.net
&nbsp;
- &#45;&#45;- 0.Description &#45;&#45;-
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from
C, Java and Perl with a couple of unique PHP-specific features thrown in. The
goal of the language is to allow web developers to write dynamically generated
pages quickly.
&nbsp;
A nice introduction to PHP by Stig Sather Bakken can be found at
http://www.zend.com/zend/art/intro.php on the Zend website. Also, much  of the
PHP Conference Material is freely available.
&nbsp;
Session support in PHP consists of a way to preserve certain data across
subsequent accesses. This enables you to build more customized applications and
increase the appeal of your web site.
&nbsp;
A visitor accessing your web site is assigned a unique id, the so-called
session id. This is either stored in a cookie on the user side or is propagated
in the URL.
&nbsp;
session.save_path defines the argument which is passed to the save handler. If
you choose the default files handler, this is the path where the files are
created. Defaults to /tmp. See also session_save_path().
&nbsp;
There is an optional N argument to this directive that determines the number of
directory levels your session files will be spread around in. For example,
setting to &#039;5;/tmp&#039; may end up creating a session file and location like
/tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If . In order to use N you
must create all of these directories before use. A small shell script exists in
ext/session to do this, it&#039;s called mod_files.sh. Also note that if N is used
and greater than 0 then automatic garbage collection will not be performed, see
a copy of php.ini for further information. Also, if you use N, be sure to
surround session.save_path in &quot;quotes&quot; because the separator (;) is also used
for comments in php.ini.
&nbsp;
- &#45;&#45;- 1. session.save_path safe mode and open basedir bypass &#45;&#45;-
session.save_path can be set in ini_set(), session_save_path() function. In
session.save_path there must be path where you will save yours tmp file. But
syntax for session.save_path can be:
&nbsp;
[/PATH]
&nbsp;
OR
&nbsp;
[N;/PATH]
&nbsp;
N - can be a string.
&nbsp;
EXAMPLES:
&nbsp;
1. session_save_path(&quot;/DIR/WHERE/YOU/HAVE/ACCESS&quot;)
2. session_save_path(&quot;5;/DIR/WHERE/YOU/HAVE/ACCESS&quot;)
&nbsp;
and
&nbsp;
3.
session_save_path(&quot;/DIR/WHERE/YOU/DONT/HAVE/ACCESS\0;/DIR/WHERE/YOU/HAVE/ACCESS&quot;)</pre>
</blockquote>
<pre>CACHE_LIMITER_FUNC(public)
{
        char buf[MAX_STR + 1];
        struct timeval tv;
        time_t now;
&nbsp;
        gettimeofday(&amp;tv, NULL);
        now = tv.tv_sec + PS(cache_expire) * 60;
#define EXPIRES &quot;Expires: &quot;
        memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1);
        strcpy_gmt(buf + sizeof(EXPIRES) - 1, &amp;now);
        ADD_HEADER(buf);
&nbsp;
        snprintf(buf, sizeof(buf) , &quot;Cache-Control: public, max-age=%ld&quot;, PS(cache_expire) * 60); /* SAFE */
        ADD_HEADER(buf);
&nbsp;
        last_modified(TSRMLS_C);
}
&nbsp;
CACHE_LIMITER_FUNC(private_no_expire)
{
        char buf[MAX_STR + 1];
&nbsp;
        snprintf(buf, sizeof(buf), &quot;Cache-Control: private, max-age=%ld, pre-check=%ld&quot;, PS(cache_expire) * 60, PS(cache_expire) * 60); /* SAFE */
        ADD_HEADER(buf);
&nbsp;
        last_modified(TSRMLS_C);
}
&nbsp;
CACHE_LIMITER_FUNC(private)
{
        ADD_HEADER(&quot;Expires: Thu, 19 Nov 1981 08:52:00 GMT&quot;);
        CACHE_LIMITER(private_no_expire)(TSRMLS_C);
}
&nbsp;
CACHE_LIMITER_FUNC(nocache)
{
        ADD_HEADER(&quot;Expires: Thu, 19 Nov 1981 08:52:00 GMT&quot;);
        /* For HTTP/1.1 conforming clients and the rest (MSIE 5) */
        ADD_HEADER(&quot;Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0&quot;);
        /* For HTTP/1.0 conforming clients */
        ADD_HEADER(&quot;Pragma: no-cache&quot;);
}
&nbsp;
static php_session_cache_limiter_t php_session_cache_limiters[] = {
        CACHE_LIMITER_ENTRY(public)
        CACHE_LIMITER_ENTRY(private)
        CACHE_LIMITER_ENTRY(private_no_expire)
        CACHE_LIMITER_ENTRY(nocache)
        {0}
};
&nbsp;
static int php_session_cache_limiter(TSRMLS_D)
{
        php_session_cache_limiter_t *lim;
&nbsp;
        if (PS(cache_limiter)[0] == &#039;\0&#039;) return 0;
&nbsp;
        if (SG(headers_sent)) {
                char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
                int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
&nbsp;
                if (output_start_filename) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Cannot send session cache limiter - headers already sent (output started at %s:%d)&quot;,
                                output_start_filename, output_start_lineno);
                } else {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Cannot send session cache limiter - headers already sent&quot;);
                }
                return -2;
        }
&nbsp;
        for (lim = php_session_cache_limiters; lim-&gt;name; lim++) {
                if (!strcasecmp(lim-&gt;name, PS(cache_limiter))) {
                        lim-&gt;func(TSRMLS_C);
                        return 0;
                }
        }
&nbsp;
        return -1;
}</pre>
<pre>static void php_session_send_cookie(TSRMLS_D)
{
        smart_str ncookie = {0};
        char *date_fmt = NULL;
        char *e_session_name, *e_id;
&nbsp;
        if (SG(headers_sent)) {
                char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
                int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
&nbsp;
                if (output_start_filename) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Cannot send session cookie - headers already sent by (output started at %s:%d)&quot;,
                                output_start_filename, output_start_lineno);
                } else {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, &quot;Cannot send session cookie - headers already sent&quot;);
                }
                return;
        }
&nbsp;
        /* URL encode session_name and id because they might be user supplied */
        e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name)), NULL);
        e_id = php_url_encode(PS(id), strlen(PS(id)), NULL);
&nbsp;
        smart_str_appends(&amp;ncookie, COOKIE_SET_COOKIE);
        smart_str_appends(&amp;ncookie, e_session_name);
        smart_str_appendc(&amp;ncookie, &#039;=&#039;);
        smart_str_appends(&amp;ncookie, e_id);
&nbsp;
        efree(e_session_name);
        efree(e_id);
&nbsp;
        if (PS(cookie_lifetime) &gt; 0) {
                struct timeval tv;
                time_t t;
&nbsp;
                gettimeofday(&amp;tv, NULL);
                t = tv.tv_sec + PS(cookie_lifetime);
&nbsp;
                if (t &gt; 0) {
                        date_fmt = php_std_date(t TSRMLS_CC);
                        smart_str_appends(&amp;ncookie, COOKIE_EXPIRES);
                        smart_str_appends(&amp;ncookie, date_fmt);
                        efree(date_fmt);
                }
        }
&nbsp;
        if (PS(cookie_path)[0]) {
                smart_str_appends(&amp;ncookie, COOKIE_PATH);
                smart_str_appends(&amp;ncookie, PS(cookie_path));
        }
&nbsp;
        if (PS(cookie_domain)[0]) {
                smart_str_appends(&amp;ncookie, COOKIE_DOMAIN);
                smart_str_appends(&amp;ncookie, PS(cookie_domain));
        }
&nbsp;
        if (PS(cookie_secure)) {
                smart_str_appends(&amp;ncookie, COOKIE_SECURE);
        }
&nbsp;
        if (PS(cookie_httponly)) {
                smart_str_appends(&amp;ncookie, COOKIE_HTTPONLY);
        }
&nbsp;
        smart_str_0(&amp;ncookie);
&nbsp;
        /*      &#039;replace&#039; must be 0 here, else a previous Set-Cookie
                header, probably sent with setcookie() will be replaced! */
        sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC);
}</pre>
<p><a href="http://www.askapache.com/php/php-session-hack.html"></a><a href="http://www.askapache.com/php/php-session-hack.html">PHP Session File Hacks</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/php/php-session-hack.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30x Faster WP-Super Cache Site Speed</title>
		<link>http://www.askapache.com/web-hosting/super-speed-secrets.html</link>
		<comments>http://www.askapache.com/web-hosting/super-speed-secrets.html#comments</comments>
		<pubDate>Thu, 18 Mar 2010 15:43:21 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WiredTree]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[Boot]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[devshm]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[Hard Drive]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[ionice]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[memory bandwidth]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Private Server]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[SLRAM]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[speed improvements]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[tmpfs]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[Vulnerability]]></category>
		<category><![CDATA[webhosts]]></category>
		<category><![CDATA[WP-Super Cache]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3220</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/web-hosting/super-speed-secrets.html" id="id0"></a></p>
<p>NOT a typo..  30x is measurable, well-documented, and easily tested.  This is what <strong>open-source</strong> is about.   I haven’t had time to post much the past year, I'm always working!  So I wanted to make up for that by publishing an article on a topic that would blow your mind and be something that you could actually start using and really get some benefit out of it. This is one of those articles that the majority of web hosting companies would love to see in paperback, <strong>so they could burn it.</strong></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/web-hosting/super-speed-secrets.html"><img src="http://uploads.askapache.com/2009/09/top.jpg" alt="Top showing swap and memory" title="Top showing swap and memory" width="434" height="52" class="size-full wp-image-3270" /></a></p>
<p>I haven&#8217;t had time to post much the past year, so I wanted to make up for that by publishing an article on a topic that would blow your mind and be something that you could actually start using and really get some benefit out of it.  This is one of those articles that the majority of web hosting companies would love to see in paperback, <strong>so they could burn it</strong>.  Now ask yourself, if a webhost makes money based on how much memory, bandwidth, and data used by a customer, what would they not want their customers to do?  That&#8217;s right, they do not want their customers to learn how to minimize and drastically reduce these moneymakers.  They get giddy when you complain about slow-site-speed, or that it takes a long time for your site to load, because they have exactly the right answer- upgrade your memory, bandwidth, and data by purchasing a more expensive plan.</p>
<p class="anote"><strong>WARNING</strong>!!  This article has some seriously advanced stuff in it, pretty far beyond my skill level as well (getting there).  I personally shutdown some of my own servers with various webhosts because of this.. Note I said personally, not intentionally.  Even after spending almost a year (this has been in my drafts folder a long time) using TMPFS on as many machines as I can, I still make mistakes (gotta pay attention!) and lose a tmpfs folder..   Oh and if you go experimenting with this stuff on your web host, you will almost definately, most certainly be on the road to getting your account terminated if you are with one of the cheap hosts.  They hate this stuff because it cuts right into the heart of their profit curves and can seriously disrupt a poorly configured machine.  DO NOT TRY THIS!!  (except and of course on your own development machines).   Of course the whole point of this article is how you can take advantage of this incredible filesystem to get crazy speed improvements..  Those are the follow up articles ;)</p>
<p>For those of you who thought modifying your server httpd.conf and htaccess files is very dangerous, you are right.  But this is not like that, this is dangerous in the sense that if you try to rush through with your super amazing &#8220;copy and paste skills&#8221; (script kids) you will easily lose entire folders.  That&#8217;s because TMPFS is stored in RAM/Memory, and upon reboot RAM is cleared.  I personally loathe disclaimers, and if you look around you will see there aren&#8217;t many even with all my sloppy poorly documented articles&#8230;  So be careful if you feel up to going further.</p>
<h2>Introducing tmpfs</h2>
<p>If I had to <strong>explain tmpfs</strong> in one breath, I&#8217;d say that tmpfs is like a ramdisk, but different. Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it&#8217;s there. All in all, this makes tmpfs the niftiest RAM-based filesystem I&#8217;ve had the opportunity to meet.</p>
<h2>Beware of WebHosts</h2>
<p>What is a modern day web hosting company?  What costs do they actually have?  A webhost&#8217;s only unique ability is their connection to the Internet.  That is why you can see such tremendous link speed.  Other than that they consist of servers that are getting smaller and cheaper for them every month.  The servers they use are generally just like any computer, except much larger and built specifically for multi-tasking.</p>
<blockquote cite="http://content.dell.com/us/en/enterprise/virtualization-what-is-it.aspx">
<p>Virtualization allows you to run multiple applications and operating systems independently on a single server. Additionally, administrators can quickly move workloads from one virtual workspace to another — easily prioritizing business needs while maximizing server resources&#8230;.</p>
<p>Virtualization removes the limitations of the traditional IT approach, enabling <strong>a single PowerEdge server</strong> to operate <strong>multiple applications simultaneously in &#8220;virtual machines&#8221;</strong></p>
</blockquote>
<h2>Hosting Company Tricks</h2>
<p>Web hosts like to vaguely describe their products as if you are buying your own powerful machine, but in reality you get placed on the same machine as hundreds or thousands of other customers, and the server basically creates an operating system for each customer using virtualization technology.  Everyone on the machine literally is sharing the same RAM and resources, many times even sharing IP address&#8217;s, and the virtualization software lets them limit the amount of memory / cpu / disk / and bandwidth for each of these virtual machines.  That is why so often when a web host has an outage they make big public announcements and it appears that hundreds or thousands of their customers have been affected.. One of their server farm machines goes offline and it literally takes down all the customers virtualized machines with it.</p>
<h3>Why it gets Evil</h3>
<p>Don&#8217;t get me wrong, I absolutely love this technology, both the hardware virtualization and the software side, but what I truly do not appreciate is how these companies take advantage of their customers every day and know it.  Here&#8217;s what they do, they make justifications about why one plan costs more than another, and these justifications are always about the same thing:  CPU&#8217;s, how fast the data can crunch..  RAM/Memory: How fast and how much your server can handle in terms of traffic&#8230; Disk Usage:  How much storage you have&#8230; And finally bandwidth: How fast can people get data off your sites, and how many people can connect.</p>
<p>Now lets think for a second.  The webhost has a BIG computer/server/machine that has MASSIVE amounts of RAM, DISK, PROCESSING power, and NETWORK bandwidth.. but just like anything they all have limits.   So if this machine has 10GB of RAM, and the webhost offered plans that have 1GB of RAM, then on that machine they can only have 10 customers right?  WRONG.  If each customer pays $100/month, then of course they would love to have as many customers on that machine as possible.  This builtin incentive is just the reality and isn&#8217;t anyone fault.</p>
<h3>Where it gets Evil</h3>
<p>Here&#8217;s what goes on.. all the host advertises is the 1GB of guaranteed RAM with your machine, but for even if the web server was fairly busy it would never use all of that ram because all the software is careful not to use too much, or has no need for any RAM.  Runtime libraries and internal caches use ram, but it&#8217;s not directly accessed by the customer, only the software.   What happens is when those 10 customers aren&#8217;t using 100% of their ram, which never happens, then the virtualization technology can use that RAM elsewhere.  So technically you do have 1GB of RAM available, but if you aren&#8217;t using it then it is essentially FREE RAM that they can sell to another customer.  The only way this wouldn&#8217;t work of course is if all 11 customers somehow used 100% of RAM simultaneously, at that point the 11th customer would be ramless.  But that is impossible because the system is a load-balancing system that provides both an upper and a lower limit to how much RAM is allotted to each virtual machine.</p>
<p>It sounds unrealistic but I see server farms all the time that are stuffed full of virtual machines, like situations where there are 100 1GB customers all sharing 10GB of RAM..  no-one uses the whole 1GB allotted to them as the maximum amount they can use, and they don&#8217;t know because it appears they have a lot of free RAM, but really that is virtual RAM and could be used by anyone else on the machine.</p>
<h3>Where it gets Fun (for me)</h3>
<p><a href="http://www.askapache.com/linux-unix/bash-power-prompt.html"class="IFL" ><img src="http://uploads.askapache.com/2010/03/askapache-htop.jpg" alt="The HTOP command in full color to manage mysql" title="The HTOP command in full color to manage mysql" width="404" height="176" class="size-full wp-image-4149" /></a>This is actually even worse for anyone who is using what they call &#8220;shared-hosting&#8221; which is the budget hosting that is the most common.  With shared-hosting there is actually some skill involved on the hosting companies part, like real linux skills.  In this setup they may or more often may not use any virtualization software.  It&#8217;s just a vanilla multi-user server machine where each customer gets a restricted unix account that powers their website using the same system as thousands of others on the box.  This is usually dirt cheap because it costs so little to do, but alot of companies charge outrageous amounts for shared-hosting because they make it look really full-featured, which it can be, they just don&#8217;t mention 1000 other people use the same machine, hard-drive, /tmp directory, network device, IP address, etc..  Alot of the times the cheaper end of the spectrum is where the most gifted system administrators are located, they are so good with linux administration that they could fit 10 customers and 100 websites on an XBOX converted to run linux, and you&#8217;d think you got a great deal until you found out! lol.  Anyone alive is able to buy more hardware to expand their capacity to take on more customers,  but it takes a lot of knowhow and real skill to have that many users on 1 machine.  I&#8217;ve seen pretty extreme cases that are analogous to the XBOX example (which is possible by the way).<br class="C" /></p>
<p>I personally love shared-hosting environments, because for those of us who know almost as much or more than the system administrators running the machine we are able to use a disproportionate (legally) amount of the CPU and RAM available on the system.  So for example my sites would  all show up fast and be able to handle more traffic than several other customers combined.  Not because<br />
anything has been circumvented, but because I am able to access and utilize as much of the guaranteed 1GB of RAM that I am paying for every month, which is usually just a few bucks.  The downside is that when you have corporate sites or really high-traffic sites then you are forced to move to a more powerful machine..  </p>
<p>This leads to a familiar situation for some of you..  When your site starts becoming popular and you are getting a lot of traffic, this means that your site could be using 10x the amount of RAM and Bandwidth of any other customer in that server farm.  And what that really means to the webhost is that you are costing them 10x what anyone else is..  And if they removed you, they would have the space for 10 new customers to take your place, and they would make 10x more money.  DreamHost is notorious for terminating accounts because of that..  It happened to me except I was given the option to pay 5x more a month for their &#8220;upgrade&#8221; to a VPS.  Giant shared-hosts advertise like crazy how they offer unlimited bandwidth, but <strong>when you start using 100x more bandwidth than anyone on your server you are costing them 100x what you are paying them, every month</strong>.  That&#8217;s why you will never see a webhost offering this kind of unlimited bandwidth that doesn&#8217;t require you to sign a contract giving them permission to terminate your account <em>for any reason</em>.  Seriously read the fine print at DreamHost or anywhere else, it&#8217;s included because that is a core part of their business to terminate anyone using too much bandwidth since that is bandwidth they can&#8217;t sell to dozens of other customers.  That&#8217;s why I eventually closed my account with them and moved to a legitimate company, it&#8217;s a great host for spammers though.</p>
<p>Back in the mid-90&#8242;s I was doing a lot of war-dialing with my modem and discovering all sorts of networks and machines, many of them were Unix and Solaris based public systems, and when I managed to gain access to the system and found myself staring at a unix shell I was very excited but also a total idiot.  In those days of using the phone networks to research unknown systems it was very difficult for anyone to actually get the phone company to trace a call, so instead of what happens today where it is child&#8217;s play to trace an IP address, back then it was a very real back-and-forth battle between the system admin and whoever was gaining access to their system.  Essentially, I would gain a shell or some kind of terminal, and just go at it trying to figure out what it could do, trying all kinds of commands.  Inevitably this would eventually alert even the laziest admin and they would proceed to attempt to lock me out. It was great sport and extremely addictive.  When my favorite system (a massive sun machine in the basement of a big library) finally locked me out and I couldn&#8217;t get back in I went to my local library and got some reading material &#8212; one of my favorites was the red hat bible.  I was able to acquire my own computer and the first thing I did was install red hat linux onto it from the discs included with the book.  For the next several years I was essentially offline, all we had at home was a modem and it was becoming difficult to locate any more systems in my area code.. I was into phreaking of course as well, but I never was able to make free long-distance war-dialing a reality.  So I just read the books and learned what I could.  I would also goto the library when I could in order to use their machines which were connected to the internet (before aol it was much different than today&#8217;s internet) and since my time was short I would download as many documents as I could so that I could read them offline.  The TLDP documentation that we know today was around back then in various forms, and I read every HOWTO in the index, though not understanding half.  The other big resource I found for really intense reading was the <a href="http://www.kernel.org/doc/Documentation/" rel="nofollow" >kernel documentation</a>, which admitedly I still don&#8217;t comprehend 1/4th of..   I try and peruse all the new documents when a new kernel is released, since the kernel is where all the real action is, hence the military authoritative name, and that is how I discovered one of the coolest features of Linux that I have found.  TMPFS!</p>
<h2>TMPFS kills the RAMDISK</h2>
<p>Ok so we all know what RAM is, it&#8217;s the memory cards that most people never see that is used by the computer to store and access data that all programs need.  RAM is very expensive compared to most PC components, because it&#8217;s what makes a computer blazing fast or slow.  So real quick lets look at a few (there are not many) ways that various linux hackers use RAM in non-conventional ways in the past.</p>
<p>Tmpfs is a file system which keeps all files in virtual memory.  Everything is temporary in the sense that no files will be created on your hard drive. If you reboot, everything in tmpfs will be lost.</p>
<p>In contrast to RAM disks, which get allocated a fixed amount of physical RAM, tmpfs grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space.</p>
<p>Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it&#8217;s there. All in all, this makes tmpfs the niftiest RAM-based filesystem I&#8217;ve had the opportunity to meet.</p>
<p>If I had to <strong>explain tmpfs</strong> in one breath, I&#8217;d say that tmpfs is like a ramdisk, but different. Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it&#8217;s there. All in all, this makes tmpfs the niftiest RAM-based filesystem I&#8217;ve had the opportunity to meet.</p>
<p><br class="C" /></p>
<p>What kind of filesystem is used on your server to store all your site files?  EXT4, REISERFS, EXT3, NFS, etc.. are the usual filesystems, Windows users are limited to the NTFS filesystem.   A filesystem is different than a device, a device is a hard-drive disk.  A filesystem is how the device is formatted to allow for file and folder structures.  A hard drive is slow compared to RAM, no question about that.  So what if instead of your server serving files off a hard-drive it served files stored in RAM?  <strong>30x faster thats what happens!</strong></p>
<p class="wnote">I just figured out how to store my cached static files created by WP-Super Cache in my server&#8217;s RAM, and the difference is unbelievable.  My &#8220;AskApache Crazy Cache&#8221; plugin basically forces WP-Super Cache, Hyper Cache, etc.. to recreate a static cached file for every page on a blog.  For the AskApache.com site this takes around 3 minutes to complete.  Once I switched to using this new method of storing the files on RAM I am able to re-cache the entire site in about 15 seconds!!!!</p>
<p class="wnote">tmpfs is a dynamically expandable/shrinkable ramdisk, and will<br />
# use almost no memory if not populated with files</p>
<blockquote cite="">
<p>Tmpfs is a file system which keeps all files in virtual memory.</p>
<p>Everything in tmpfs is temporary in the sense that no files will be created on your hard drive. If you unmount a tmpfs instance, everything stored therein is lost.</p>
<p>tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space. It has maximum size limits which can be adjusted on the fly via &#8216;mount -o remount &#8230;&#8217;</p>
<p>If you compare it to ramfs (which was the template to create tmpfs) you gain swapping and limit checking. Another similar thing is the RAM disk (/dev/ram*), which simulates a fixed size hard disk in physical RAM, where you have to create an ordinary filesystem on top. Ramdisks cannot swap and you do not have the possibility to resize them.</p>
<p>Since tmpfs lives completely in the page cache and on swap, all tmpfs pages currently in memory will show up as cached. It will not show up as shared or something like that. Further on you can check the actual RAM+swap use of a tmpfs instance with df(1) and du(1).</p>
</blockquote>
<p>Both tmpfs and ramfs mount will give you the power of fast reading and writing files from and to the primary memory. When you test this on a small file, you may not see a huge difference. You’ll notice the difference only when you write large amount of data to a file with some other processing overhead such as network.</p>
<h2>TMPFS uses RAM+SWAP</h2>
<p>TMPFS is another filesystem with uniquely cool capabilities.  It stores any files contained within it on RAM and in SWAP which means your server can access any files stored on TMPFS without even having to access the disk, which according to technical stats is around 30 times faster than accessing a file off disk.</p>
<p>Some other cool aspects of TMPFS are that it intelligently and automatically sizes itself to be just alittle bigger then it needs to be.  So when you remove files to a folder stored on a TMPFS filesystem, the TMPFS filesystem shrinks by allocating less RAM and/or SWAP.  Conversely when adding files to TMPFS it grows larger.  You can set the max-size and max-number-of-files as a mount option to make sure your TMPFS never uses all of the available RAM and SWAP, which would halt your server.</p>
<h3>Swap</h3>
<p>Find the swap size.</p>
<pre># free -m -t
             total       used       free     shared    buffers     cached
Mem:           458         93        364          0          0          0
-/+ buffers/cache:         93        364
Swap:          900          0        900
Total:        1358         93       1264</pre>
<pre>Adding 3004144k swap on /dev/sdb2.  Priority:-1 extents:1 across:3004144k
Adding 2096472k swap on /dev/sda3.  Priority:-2 extents:1 across:2096472k</pre>
<h2>Using TMPFS for Cache</h2>
<p>The method here will show how to create and use a TMPFS filesystem to hold all the static files created by WP-Super Cache.  These static files are served to visitors instead of loading php for every request, so by moving those static files to TMPFS your server will be able to access and start sending your site to the browser 30x faster!</p>
<p>The WP-Super Cache plugin stores all the static files in the wp-content/cache folder of your WordPress installation, so to enable TMPFS we simply will create a new TMPFS filesystem and mount it to the wp-content/cache folder.  That makes anything in that folder (all the static files) be part of the TMPFS filesystem.</p>
<h2>Boosting Cache with TMPFS</h2>
<p>There are a lot of maybe new concepts surrounding TMPFS and it may seem too complicated, but the process of actually setting up a robust tmpfs to use for wp-super-cache&#8217;s cache folder is actually very simple.  As long as you have shell access to your server and the permissions required (any sudo or private server should be good to go) you can set this up in a couple minutes and not really have to give it a second thought or debug anything.  Here&#8217;s the process I&#8217;ve used on several client sites.</p>
<ol>
<li>Create a TMPFS Filesystem and Mount at /wp-content/cache/</li>
<li>Restore TMPFS Cached Files across Reboots</li>
<li>Keep a semi-current mirror of the TMPFS files on Disk</li>
</ol>
<p><br class="C" /></p>
<h3>Create TMPFS at wp-content/cache</h3>
<p>/etc/fstab</p>
<pre>tmpfs /home/askapache/wp-content/cache tmpfs defaults,size=2g,noexec,nosuid,uid=648,gid=648,mode=1755 0 0</pre>
<h3>Restoring TMPFS across Reboots</h3>
<p>In /etc/rc.local</p>
<pre>ionice -c3 -n7 nice -n 19 rsync -ahv &#45;-stats &#45;-delete /_b/tmpfs/cache/ /home/askapache/wp-content/cache/ 1&gt;/dev/null</pre>
<h3>Mirroring TMPFS to Disk</h3>
<p>Cronjob entry</p>
<pre>*/5 * * * * /usr/bin/ionice -c3 -n7 /bin/nice -n 19 /usr/bin/rsync -ah &#45;-stats &#45;-delete /home/askapache/wp-content/cache/ /_b/tmpfs/cache/ 1&gt;/dev/null</pre>
<p><span id="more-3220"></span></p>
<h2>/tmp, /var/run, and /var/lock</h2>
<p>The directories /tmp, /var/run, and /var/lock contain files that are not needed across reboots.  This means they are ideal candidates for tmpfs.  HEre&#8217;s how to do it.</p>
<pre>tmpfs /var/run tmpfs defaults,rw,nosuid,mode=0755 0 0</pre>
<pre>tmpfs /var/lock tmpfs defaults,rw,noexec,nosuid,nodev,mode=1777 0 0</pre>
<h2>Resize /dev/shm</h2>
<p>You can view your current /dev/shm size with the command <code>df -ha|grep /dev/shm</code> then if you want to resize that use the command:</p>
<pre>mount -t tmpfs -o remount,size-2G,rw,nosuid,nodev tmpfs /dev/shm</pre>
<pre>Secure /dev/shm:
&nbsp;
Step 1: Edit your /etc/fstab:
&nbsp;
nano -w /etc/fstab
&nbsp;
Locate:
&nbsp;
none /dev/shm tmpfs defaults,rw 0 0
&nbsp;
Change it to:
&nbsp;
none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0
&nbsp;
Step 2: Remount /dev/shm:
&nbsp;
mount -o remount /dev/shm
&nbsp;
guilt makes extensive use of the &#039;$$&#039; shell variable for temporary
files in /tmp. This is a serious security vulnerability; on multi-user
systems it allows an attacker to clobber files with something like the
following:
&nbsp;
for i in `seq 1 32768`; do
ln -sf /etc/passwd /tmp/guilt.log.$i;
done
&nbsp;
(In this example, if root does e.g. &#039;guilt push&#039;, /etc/passwd will get
clobbered.)</pre>
<p><br class="C" /></p>
<h3>Securing and Using /tmp</h3>
<ul>
<li><a href="http://www.sysadmin.md/secure-temporary-folders-on-existing-unix-or-linux-systems.html" rel="nofollow" >Secure temporary folders on existing Unix or Linux systems</a></li>
<li><a href="https://wiki.torproject.org/noreply/TheOnionRouter/OperationalSecurity" rel="nofollow" >Encrypt Storage and Swap Space</a></li>
</ul>
<p><a id="tmpfs-mount"></a></p>
<h2>tmpfs mount parameters</h2>
<p>A good way to find a good tmpfs upper-bound is to use top to monitor your system&#8217;s swap usage during peak usage periods. Then, make sure that you specify a tmpfs upper-bound that&#8217;s slightly less than the sum of all free swap and free RAM during these peak usage times. </p>
<p><strong>mode=1777</strong> sets sticky bit on directory. Only file owners can delete files in this directory.</p>
<p>The following parameters accept a suffix k, m or g for Ki, Mi, Gi (binary kilo, mega and giga) and can be changed on remount.</p>
<ul>
<li><strong>size</strong>:  Override default maximum size of the filesystem.  The size is given in bytes, and rounded down to entire pages.  The default is half of the memory.The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs instances the machine will deadlock since the OOM handler will not be able to free that memory.</li>
<li><strong>nr_inodes</strong>:  Set number of inodes.</li>
<li><strong>nr_blocks</strong>:  Set number of blocks.</li>
<li><strong>mode</strong>: The permissions as an octal number</li>
<li><strong>uid</strong>: The user id</li>
<li><strong>gid</strong>: The group id</li>
</ul>
<pre>mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs</pre>
<p>Will give you tmpfs instance on /mytmpfs which can allocate 10GB RAM/SWAP in 10240 inodes and it is only accessible by root.</p>
<p><a id="tmp-tmpfs"></a></p>
<h2>Using tmpfs for /tmp storage</h2>
<p>Many users find it very convenient to use tmpfs for /tmp and /var/tmp which does a number of positive things.  Any temporary files are instead created in RAM not your hard-drive, which means that reading/writing/accessing those temporary files by various processes doesn&#8217;t slow down your hard-drive read/writes/accesses for your other processes.  This also has a side-effect of making your hard-drive have a longer life as it reduces activity by a huge amount.</p>
<p>Remember that tmpfs uses both RAM and swap, so make sure your machine has a large swapfile, like gigabytes.  If your tmpfs consumes all the swap and RAM then you are screwed, so make sure that you correctly set the mount options for the tmpfs so that it doesn&#8217;t do that.  If your /tmp or /var/tmp gets filled with tmp files that for some reason don&#8217;t get deleted except at reboot, and your machine has a very high uptime, then you will want to run some cron jobs to periodically clean the /tmp and /var/tmp directories of older files&#8230;</p>
<p>Here&#8217;s an example scenario: let&#8217;s say that we have an existing filesystem mounted at /tmp. However, we decide that we&#8217;d like to start using tmpfs for /tmp storage.</p>
<p>with recent 2.4 kernels, you can mount your new /tmp filesystem without getting the &#8220;device is busy&#8221; error: </p>
<pre>mount tmpfs /tmp -t tmpfs -o size=64m</pre>
<p>With a single command, your new tmpfs /tmp filesystem is mounted at /tmp, on top of the already-mounted partition, which can no longer be directly accessed. However, while you can&#8217;t get to the original /tmp, any processes that still have open files on this original filesystem can continue to access them. And, if you umount your tmpfs-based /tmp, your original mounted /tmp filesystem will reappear. In fact, you can mount any number of filesystems to the same mountpoint, and the mountpoint will act like a stack; unmount the current filesystem, and the last-most-recently mounted filesystem will reappear from underneath.</p>
<p><a id="bind-mounts"></a></p>
<h2>Bind Mounts</h2>
<p>Using bind mounts, we can mount all, or even part of an already-mounted filesystem to another location, and have the filesystem accessible from both mountpoints at the same time!</p>
<p>For example, you can use bind mounts to mount your existing /tmp filesystem to /sites/askapache.com/tmp, as follows:</p>
<pre>mount &#45;-bind /tmp /sites/askapache.com/tmp</pre>
<p>Now, if you look inside /sites/askapache.com/tmp, you&#8217;ll see your /tmp filesystem and all its files. And if you modify a file on your /tmp filesystem, you&#8217;ll see the modifications in /sites/askapache.com/tmp as well. This is because <strong>they are one and the same filesystem; the kernel is simply mapping the filesystem to two different mountpoints for us</strong>. </p>
<p>Note that when you mount a filesystem somewhere else, any filesystems that were mounted to mountpoints inside the bind-mounted filesystem will not be moved along. In other words, if you have /tmp/cache on a separate filesystem, the bind mount we performed above will leave /sites/askapache.com/tmp/cache empty. You&#8217;ll need an additional bind mount command to allow you to browse the contents of /tmp/cache at /sites/askapache.com/tmp/cache:</p>
<pre>mount &#45;-bind /tmp/cache /sites/askapache.com/tmp/cache</pre>
<h3>Bind mounting and /dev/shm</h3>
<p>glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for POSIX shared memory (shm_open, shm_unlink). Adding the following line to /etc/fstab should take care of this:</p>
<pre>tmpfs  /dev/shm  tmpfs  defaults  0 0</pre>
<p>Many systems by default have a tmpfs filesystem mounted at /dev/shm that defaults to a size of half of your physical RAM without swap.  Say you decide that you&#8217;d like to start using tmpfs for /tmp, which currently lives on your root filesystem. Rather than mounting a new tmpfs filesystem to /tmp (which is possible), you may decide that you&#8217;d like the new /tmp to share the currently mounted /dev/shm filesystem. However, while you could bind mount /dev/shm to /tmp and be done with it, your /dev/shm contains some directories that you don&#8217;t want to appear in /tmp. So, what do you do? How about this:</p>
<pre>mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount &#45;-bind /dev/shm/tmp /tmp</pre>
<p>In this example, we first create a /dev/shm/tmp directory and then give it 1777 perms, the proper permissions for /tmp. Now that our directory is ready, we can mount /dev/shm/tmp, and only /dev/shm/tmp to /tmp. So, while /tmp/foo would map to /dev/shm/tmp/foo, there&#8217;s no way for you to access the /dev/shm/bar file from /tmp.</p>
<p><br class="C" /></p>
<p><a id="default-tmpfs-workaround"></a></p>
<h2>/etc/default/tmpfs WorkAround</h2>
<pre>$ cat /etc/default/tmpfs
# SHM_SIZE sets the maximum size (in bytes) that the /dev/shm tmpfs can use.
# If this is not set then the size defaults to the value of TMPFS_SIZE
# if that is set; otherwise to the kernel&#039;s default.
#
# The size will be rounded down to a multiple of the page size, 4096 bytes.
SHM_SIZE=524288000
# TMPFS_SIZE sets the max size that /dev/shm can use.  By default, the
# kernel sets this upper limit to half of available memory.
TMPFS_SIZE=524288000</pre>
<p><a id="rsync-vs-cp"></a></p>
<h2>RSYNC vs. CP</h2>
<pre>rsync [options]  SRC DEST
rsync -av &#45;-delete &#45;-stats /home/wincom/public_html/wp-content/cache/ /backups/tmp-mnt/cache/
-a, &#45;-archive               archive mode; same as -rlptgoD (no -H)
-r, &#45;-recursive             recurse into directories
-l, &#45;-links                 copy symlinks as symlinks
-p, &#45;-perms                 preserve permissions
-t, &#45;-times                 preserve times
-g, &#45;-group                 preserve group
-o, &#45;-owner                 preserve owner (super-user only)
-D                          same as &#45;-devices &#45;-specials
    &#45;-devices               preserve device files (super-user only)
    &#45;-specials              preserve special files
 -h, &#45;-human-readable        output numbers in a human-readable format
     &#45;-progress              show progress during transfer</pre>
<p><a id="mount-options"></a></p>
<h2>Mount Options</h2>
<p>The following options apply to any file system that is being mounted (but not every file  system  actually honors them)</p>
<ul>
<li><code>async</code> All I/O to the file system should be done asynchronously.</li>
<li><code>atime</code> Update inode access time for each access. This is the default.</li>
<li><code>auto</code> Can be mounted with the -a option.</li>
<li><code>defaults</code> Use default options: rw, suid, dev, exec, auto, nouser, and async.</li>
<li><code>dev</code> Interpret character or block special devices on the file system.</li>
<li><code>exec</code> Permit execution of binaries.</li>
<li><code>group</code> Allow an ordinary (i.e., non-root) user to mount the file system if one of his groups matches the group of the device.  This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line group,dev,suid).</li>
<li><code>mand</code> Allow mandatory locks on this filesystem. See fcntl(2).</li>
<li><code>_netdev</code> The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).</li>
<li><code>noatime</code> Do not update inode access times on this file system (e.g, for faster access on the news spool to speed up news servers).</li>
<li><code>nodiratime</code> Do not update directory inode access times on this filesystem.</li>
<li><code>noauto</code> Can only be mounted explicitly (i.e., the -a option will not cause the file system to be mounted).</li>
<li><code>nodev</code> Do not interpret character or block special devices on the file system.</li>
<li><code>noexec</code> Do not allow direct execution of any binaries on the mounted file system.  (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)</li>
<li><code>nomand</code> Do not allow mandatory locks on this filesystem.</li>
<li><code>nosuid</code> Do not allow set-user-identifier or set-group-identifier bits to take effect. (This seems safe, but is in fact rather unsafe if you have suidperl(1) installed.)</li>
<li><code>nouser</code> Forbid an ordinary (i.e., non-root) user to mount the file system.  This is the default.</li>
<li><code>owner</code> Allow an ordinary (i.e., non-root) user to mount the file system if he is the owner of the device.  This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line owner,dev,suid).</li>
<li><code>remount</code> Attempt to remount an already-mounted file system.  This is commonly used to change the mount flags for a file system, especially to make a readonly file system writeable. It does not change device or mount point.</li>
<li><code>ro</code> Mount the file system read-only.</li>
<li><code>_rnetdev</code> Like _netdev, except &#8220;fsck -a&#8221; checks this filesystem during rc.sysinit.</li>
<li><code>rw</code> Mount the file system read-write.</li>
<li><code>suid</code> Allow set-user-identifier or set-group-identifier bits to take effect.</li>
<li><code>sync</code> All I/O to the file system should be done synchronously. In case of media with limited number of write cycles (e.g. some flash drives) &#8220;sync&#8221; may cause life-cycle shortening.</li>
<li><code>dirsync</code> All directory updates within the file system should be done synchronously.  This affects the following system calls: creat, link, unlink, symlink, mkdir, rmdir, mknod and rename.</li>
<li><code>user</code> Allow  an ordinary user to mount the file system.  The name of the mounting user is written to mtab so that he can unmount the file system again.  This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).</li>
<li><code>users</code> Allow every user to mount and unmount the file system.  This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).</li>
</ul>
<p><a id="filesystems"></a></p>
<h2>Filesystems</h2>
<p>You can find out what is filesystems are in place by using one of the following linux commands:</p>
<pre>cat /etc/fstab
cat /etc/mtab
cat /proc/mounts
df -a</pre>
<h2>/etc/fstab</h2>
<pre>       /etc/fstab        file system table
       /etc/mtab         table of mounted file systems
       /etc/mtab~        lock file
       /etc/mtab.tmp     temporary file
       /etc/filesystems  a list of filesystem types to try</pre>
<p>From /etc/mtab</p>
<pre>none /tmp tmpfs size=128m,mode=1777 0 0</pre>
<p>From /proc/mounts</p>
<pre>none /tmp tmpfs rw,nodev,relatime,size=131072k 0 0</pre>
<p><br class="C" /></p>
<p><a id="fstab"></a></p>
<h2>/etc/fstab</h2>
<p>It is possible that files /etc/mtab and /proc/mounts don’t match. The first file is based only on the mount command options, but the content of the second file also depends on the kernel and others settings (e.g.  remote NFS server. In particular case  the  mount  command  may reports unreliable information about a NFS mount point and the /proc/mounts file usually contains more reliable information.)</p>
<p>This file is used in three ways:</p>
<ol>
<li>The following command (usually given in a bootscript) causes all file systems mentioned in fstab (of the proper type and/or having or not having the proper options) to be mounted as indicated, except for those whose line contains the noauto keyword. Adding the -F option will  make  mount  fork,  so that the filesystems are mounted simultaneously.
<pre>mount -a [-t type] [-O optlist]</pre>
</li>
<li>When mounting a file system mentioned in fstab, it suffices to give only the device, or only the mount point.</li>
<li>Normally, only the superuser can mount file systems.  However, when fstab contains the user option on a line, anybody can mount the corresponding system.</li>
</ol>
<p>The programs mount and umount maintain a list of currently mounted file systems in the file /etc/mtab.</p>
<p>Only the user that mounted a filesystem can unmount it again.  If any user should be able to unmount, then use users instead of user in the fstab line.  The owner option is similar to the user option, with the restriction that the user must be the owner of the special file.  The group option is similar, with the restriction that the user must be member of the group of the special file.</p>
<p>The order of records in fstab is important because fsck(8), mount(8), and umount(8) sequentially iterate through fstab doing their thing.</p>
<h3>The first field, (fs_spec)</h3>
<p>Describes the block special device or remote filesystem to be mounted.  For ordinary mounts it will hold (a link to) a block special device node (as created by mknod(8)) for the device to be mounted, like ‘/dev/cdrom’ or ‘/dev/sdb7’.  For NFS mounts one will have <code><host>:<dir></code>, e.g., ‘knuth.aeb.nl:/’.  For procfs, use ‘proc’.</p>
<p>Instead of giving the device explicitly, one may indicate the (ext2 or xfs) filesystem that is to be mounted by its UUID or volume label (cf.  e2label(8) or xfs_admin(8)), writing LABEL=<label> or UUID=<uuid>, e.g., ‘LABEL=Boot’ or  ‘UUID=3e6be9de-8139-11d1-9106-a43f08d823a6’.  This will make the system more robust: adding or removing a SCSI disk changes the disk device name but not the filesystem volume label.</p>
<h3>The second field, (fs_file)</h3>
<p>Describes the mount point for the filesystem.  For swap partitions, this field should be specified as ‘none’. If the name of the mount point contains spaces these can be escaped as ‘\040’.</p>
<p>The  third  field,  (fs_vfstype),  describes the type of the filesystem.  Linux supports lots of filesystem types, such as adfs, affs, autofs, coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly others. For more details, see mount(8).  <strong>For the filesystems currently supported by the running kernel, see /proc/filesystems</strong>.  An entry swap denotes  a  file  or  partition  to  be  used  for  swapping,  cf.  swapon(8).  An entry ignore causes the line to be ignored.  This is useful to show disk partitions which are currently unused.</p>
<h3>The fourth field, (fs_mntops)</h3>
<p>Describes the mount options associated with the filesystem.  It  is formatted as a comma separated list of options.  It contains at least the type of mount plus any additional options appropriate to the filesystem type.  For documentation on the available options for non-nfs file systems, see mount(8).  For documentation on all nfs-specific options have a look at nfs(5).</p>
<p>Common for all types of file system are the options:</p>
<ul>
<li><strong>noauto</strong>: (do not mount when &#8220;mount -a&#8221; is given, e.g., at boot time)</li>
<li><strong>user</strong>: (allow a user to mount)</li>
<li><strong>owner</strong>: (allow device owner to mount)</li>
<li><strong>pamconsole</strong>: (allow a user at the console to mount)</li>
<li><strong>comment</strong>: (e.g., for use by fstab-maintaining programs).</li>
</ul>
<h3>The fifth field, (fs_freq)</h3>
<p>Used for these filesystems by the dump(8) command to determine which filesystems need to be dumped.  If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.</p>
<h3>The  sixth  field,  (fs_passno)</h3>
<p>Used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time.  The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2.  Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware.  If the sixth field is not present or zero, a value of zero is returned and <strong>fsck will assume that the filesystem does not need to be checked</strong>.</p>
<h3>More Reading</h3>
<ul>
<li><a href="http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/" rel="nofollow" >Overview of RAMFS and TMPFS on Linux</a></li>
<li><a href='http://uploads.askapache.com/2009/09/ramfs-rootfs-initramfs.txt'>ramfs, rootfs and initramfs</a></li>
<li><a href='http://uploads.askapache.com/2009/09/tmpfs.txt'>Tmpfs is a file system which keeps all files in virtual memory</a></li>
<li><a href="http://www.ibm.com/developerworks/library/l-fs3.html" rel="nofollow" >IBM: Advanced filesystem implementor&#8217;s guide, Part 3</a></li>
<li><a href="http://en.wikipedia.org/wiki/TMPFS" rel="nofollow" >TMPFS Wikipedia Entry</a></li>
<li><a href="http://en.wikipedia.org/wiki/Shared_memory" rel="nofollow" >Shared Memory</a></li>
<li><a href="http://kevin.vanzonneveld.net/techblog/article/create_turbocharged_storage_using_tmpfs/" rel="nofollow" >Create turbocharged storage using tmpfs</a></li>
<li><a href="http://dev.mysql.com/doc/refman/4.1/en/temporary-files.html" rel="nofollow" >Where MySQL Stores Temporary Files</a></li>
<li><a href="http://www.linuxized.com/2009/05/speeding-up-firefox-with-tmpfs-and-automatic-rsync/" rel="nofollow" >speeding up firefox with tmpfs and automatic rsync</a> <a href="http://www.linuxized.com/wp-content/uploads/2009/05/speedfox" rel="nofollow" >(shell-script)</a> <a href="http://autoverse.net/blog/2009/apr/23/speed-firefox/" rel="nofollow" >Original</a></li>
<li><a href="http://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt" rel="nofollow" >kernel documentation for tmpfs</a></li>
<li><a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=386368" rel="nofollow" >initscripts: please don&#8217;t mount /dev/shm noexec</a></li>
<li><a href="http://forums.debian.net/viewtopic.php?t=16450" rel="nofollow" >HOWTO: Using tmpfs for /tmp, /var/{log,run,lock&#8230;}</a></li>
<li><a href="http://forums.gentoo.org/viewtopic-t-371889-highlight-tmpfs.html" rel="nofollow" >Gentoo Forums: Using tmpfs for /var/{log,lock,&#8230;}</a></li>
<li><a href="http://forums.gentoo.org/viewtopic-t-717117-highlight-tmpfs.html" rel="nofollow" >[TIP] Firefox and tmpfs: a surprising improvement</a></li>
</ul>
<blockquote cite="http://openquery.com/blog/experiment-mysql-tmpdir-on-tmpfs"><p>
<cite><a href="http://openquery.com/blog/experiment-mysql-tmpdir-on-tmpfs" rel="nofollow" >Experiment: MySQL tmpdir on tmpfs</a></cite></p>
<p>In MySQL, the tmpdir path is mainly used for disk-based sorts (if the sort_buffer_size is not enough) and disk-based temp tables. The latter cannot always be avoided even if you made tmp_table_size and max_heap_table_size quite large, since MEMORY tables don’t support TEXT/BLOB type columns, and also since you just really don’t want to run the risk of exceeding available memory by setting these things too large.</p>
</blockquote>
<p><br class="C" /></p>
<h2>Use tmpfs for MySQL</h2>
<pre>&#45;-tmpdir=path, -t path</pre>
<blockquote cite="http://dev.mysql.com/doc/refman/4.1/en/server-options.html#option_mysqld_tmpdir"><p>The path of the directory to use for creating temporary files. It might be useful if your default /tmp directory resides on a partition that is too small to hold temporary tables. Starting from MySQL 4.1.0, this option accepts several paths that are used in round-robin fashion. Paths should be separated by colon characters (“:”) on Unix and semicolon characters (“;”) on Windows, NetWare, and OS/2. If the MySQL server is acting as a replication slave, you should not set &#8211;tmpdir to point to a directory on a memory-based file system or to a directory that is cleared when the server host restarts. For more information about the storage location of temporary files, see Section A.1.4.4, “Where MySQL Stores Temporary Files”. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails. </p></blockquote>
<blockquote cite="http://dev.mysql.com/doc/refman/4.1/en/temporary-files.html"><p>On Unix, MySQL uses the value of the TMPDIR  environment variable as the path name of the directory in which to store temporary files. If TMPDIR  is not set, MySQL uses the system default, which is usually /tmp, /var/tmp, or /usr/tmp. </p>
<p> If the file system containing your temporary file directory is too small, you can use the &#8211;tmpdir option to mysqld to specify a directory in a file system where you have enough space.</p>
<p>Starting from MySQL 4.1, the &#8211;tmpdir option can be set to a list of several paths that are used in round-robin fashion. Paths should be separated by colon characters (“:”) on Unix and semicolon characters (“;”) on Windows, NetWare, and OS/2.<br />
Note</p>
<p>To spread the load effectively, these paths should be located on different physical disks, not different partitions of the same disk.</p>
<p>If the MySQL server is acting as a replication slave, you should not set &#8211;tmpdir to point to a directory on a memory-based file system or to a directory that is cleared when the server host restarts. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails.</p>
<p>MySQL creates all temporary files as hidden files. This ensures that the temporary files are removed if mysqld is terminated. The disadvantage of using hidden files is that you do not see a big temporary file that fills up the file system in which the temporary file directory is located.
</p></blockquote>
<p><br class="C" /></p>
<h2>Shell Script for Firefox tmpfs</h2>
<pre>#!/bin/bash
### Bind temporary directories to /dev/shm ###
# I do this instead of mounting tmpfs on the #
# directories, so less memory gets wasted.   #
##############################################
mkdir /dev/shm/{tmp,lock}
mount &#45;-bind /dev/shm/tmp /tmp
mount &#45;-bind /dev/shm/tmp /var/tmp
mount &#45;-bind /dev/shm/lock /var/lock
chmod 1777 /dev/shm/{tmp,lock}</pre>
<hr />
<p><strong>Hey!</strong> You made it!@ at least to the bottom of the page..  I still have to finish this article, so check back in a few months.</p>
<p><a href="http://www.askapache.com/web-hosting/super-speed-secrets.html"></a><a href="http://www.askapache.com/web-hosting/super-speed-secrets.html">30x Faster WP-Super Cache Site Speed</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/web-hosting/super-speed-secrets.html/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Advanced WordPress wp-config.php Tweaks</title>
		<link>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html</link>
		<comments>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 08:23:37 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Anti-Spam]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash_profile]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Elite]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Mod_Rewrite cheatsheet]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[phpinfo]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Sessions]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[umask]]></category>
		<category><![CDATA[Username]]></category>
		<category><![CDATA[wp-config.php]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3341</guid>
		<description><![CDATA[<p>The bottom line for this article is that I want to make WordPress as fast, secure, and easy to install, run, and manage because I am using it more and more for client production sites, I will work for days in order to solve an issue so that I never have to spend time on that issue again. Time is money in this industry and that is ultimately (time) what there is to gain by tweaking WordPress.</p>

<p class="cnote"><strong>Note:</strong> I spent no time on readability, this is primarily a read the code and figure it out article.. This is for advanced users looking for a reference or discussion and for those of you looking to advance.  Feedback would be great <em>if you make it that far..</em></p>]]></description>
			<content:encoded><![CDATA[<p>The bottom line for this article is that I want to make WordPress as fast, secure, and easy to install, run, and manage because I am using it more and more for client production sites, I will work for days in order to solve an issue so that I never have to spend time on that issue again. Time is money in this industry and that is ultimately (time) what there is to gain by tweaking WordPress.</p>
<p class="cnote"><strong>Note:</strong> I spent no time on readability, this is primarily a read the code and figure it out article.. This is for advanced users looking for a reference or discussion and for those of you looking to advance.  Feedback would be great <em>if you make it that far..</em></p>
<p>For a better handle on the way I like to structure web site directories, see <a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html">Optimize a Website for Speed, Security, and Easy Management</a> but note it is a bit outdated compared to what I&#8217;m doing now.  I don&#8217;t have the luxury of using only one type of server, or hosting provider anymore, so I have been working towards making things even more portable in order to move from host to host from server to server without issues i.e. my portable <a href="http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html">.bash_profile</a>.</p>
<p>So I&#8217;ve been basically experimenting various ways to accomplish that and thought I would share what I am currently doing for my benefit and hopefully get some input.  All of my WP installs run the development version, and one main idea with my setups is that upgrading is automated.  So I really keep the WordPress install clean and use plugins and wp-config.php to do all the customization.</p>
<ul>
<li>Portability &#8211; Hands-free upgrades and easy to move</li>
<li>Security &#8211; Additional security and protection</li>
<li>Speed &#8211; Less CPU and Disk I/O</li>
<li>Customization &#8211; All my favorite customizations</li>
</ul>
<h2>wp-config.php</h2>
<p>These are the main settings I use.. Seriously this is more like an interactive article, because to understand it you will need to do some code grepping.  You may want to grab a jolt.</p>
<h3>ASKAPACHE_ROOT</h3>
<p>The ASKAPACHE_ROOT variable is just a better way for me to be able to include and access all the different files in my site tree.  For instance, in my non-wp php files, I can do this:</p>
<pre>!defined(&#039;ASKAPACHE_ROOT&#039;) &amp;&amp; require $_SERVER[&#039;DOCUMENT_ROOT&#039;] . &#039;/wp-config.php&#039;;
include(ASKAPACHE_ROOT . &#039;/includes/custom-download.inc.php&#039;);</pre>
<h3>ASKAPACHE_LOCK</h3>
<p>This is one of my all-time favorite hacks, that I think is one of the most useful methods I employ as a web developer.  This allows me to use far-future-expire headers for optimum caching, while still forcing browsers to re-validate every day or so automatically, or forcing them to re-validate whenever I change the suffix.  This takes advantage of the <a href="http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html">mod_rewrite trick</a> that I use on EVERY site I run, definately worth learning. Because I practice best-practice web-standards, for every web site I create a single css file and javascript file, which I then add to the template like:</p>
<pre>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; href=&quot;http://static.askapache.com/c/apache-0&lt;?php echo ASKAPACHE_LOCK?&gt;.css&quot; /&gt;
&lt;script src=&quot;http://static.askapache.com/j/apache-0&lt;?php echo ASKAPACHE_LOCK;?&gt;.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
<pre>&lt;?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
 * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don&#039;t have to use the web site, you can just copy this file
 * to &quot;wp-config.php&quot; and fill in the values.
 *
 * @package WordPress
 */
/* http://codex.wordpress.org/Editing_wp-config.php */
&nbsp;
/** /home/liet/askapache.com */
!defined(&#039;ASKAPACHE_ROOT&#039;) &amp;&amp; define(&#039;ASKAPACHE_ROOT&#039;, str_replace(&#039;/public_html&#039;,&#039;&#039;, $_SERVER[&#039;DOCUMENT_ROOT&#039;]));
&nbsp;
/** The 008 at the end is for manual tweaking.  time() returns seconds since &#039;00:00:00 1970-01-01 UTC&#039;. */
// http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html
!defined(&#039;ASKAPACHE_LOCK&#039;) &amp;&amp; define(ASKAPACHE_LOCK&#039;, substr(time(),0,5).&#039;008&#039;); // 12533001
&nbsp;
/** absolute path to the WordPress directory */
!defined(&#039;ABSPATH&#039;) &amp;&amp; define(&#039;ABSPATH&#039;, ASKAPACHE_ROOT .&#039;/public_html/&#039;);
&nbsp;
/**
 * WP_SITEURL, defined since WordPress Version 2.2, allows the WordPress address (URL) to be defined. The valued defined is the address where your WordPress core files reside.
 * It should include the http:// part too. Do not put a slash &quot;/&quot; at the end.
 * Setting this value in wp-config.php overrides the wp_options table value for siteurl and disables the WordPress address (URL) field in the Administration &gt; Settings &gt; General panel.
 */
!defined(&#039;WP_SITEURL&#039;) &amp;&amp; define(&#039;WP_SITEURL&#039;, &#039;http://&#039;.$_SERVER[&#039;SERVER_NAME&#039;]);
&nbsp;
/**
 * WP_HOME is another wp-config.php option added in WordPress Version 2.2. Similar to WP_SITEURL,
 * WP_HOME overrides the wp_options table value for home but does not change it permanently.
 * home is the address you want people to type in their browser to reach your WordPress blog. It should include the http:// part. Also, do not put a slash &quot;/&quot; at the end.
 */
!defined(&#039;WP_HOME&#039;) &amp;&amp; define(&#039;WP_HOME&#039;, WP_SITEURL);
&nbsp;
/** no trailing slash, full paths only */
!defined(&#039;WP_CONTENT_DIR&#039;) &amp;&amp; define( &#039;WP_CONTENT_DIR&#039;, ABSPATH . &#039;wp-content&#039; );
&nbsp;
// full url - WP_CONTENT_DIR is defined further up
!defined(&#039;WP_CONTENT_URL&#039;) &amp;&amp; define( &#039;WP_CONTENT_URL&#039;, WP_SITEURL . &#039;/wp-content&#039;);
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.6.0 */
// full path, no trailing slash
!defined(&#039;WP_PLUGIN_DIR&#039;) &amp;&amp; define( &#039;WP_PLUGIN_DIR&#039;, WP_CONTENT_DIR . &#039;/plugins&#039; );
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.6.0 */
// full url, no trailing slash
!defined(&#039;WP_PLUGIN_URL&#039;) &amp;&amp; define( &#039;WP_PLUGIN_URL&#039;, WP_CONTENT_URL . &#039;/plugins&#039; );
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.1.0 */
// Relative to ABSPATH.  For back compat.
//!defined(&#039;PLUGINDIR&#039;) &amp;&amp; define( &#039;PLUGINDIR&#039;, &#039;wp-content/plugins&#039; );
&nbsp;
/** Number of autosaves to save. TRUE is default and enables post revisions, FALSE disables revisions completely. */
!defined(&#039;WP_POST_REVISIONS&#039;) &amp;&amp; define(&#039;WP_POST_REVISIONS&#039;, 150);
&nbsp;
/* ini_set(&#039;memory_limit&#039;, WP_MEMORY_LIMIT); */
!defined(&#039;WP_MEMORY_LIMIT&#039;) &amp;&amp; define(&#039;WP_MEMORY_LIMIT&#039;, &#039;64M&#039;);
&nbsp;
/** Only check at this interval for new messages. Default is 5min */
/** @since 2.9  */
!defined(&#039;WP_MAIL_INTERVAL&#039;) &amp;&amp; define(&#039;WP_MAIL_INTERVAL&#039;, 3600); // 1 hour
&nbsp;
/** Saves updated post values to post from edit window every x seconds. (default 60)
 * When editing a post, WordPress uses Ajax to auto-save revisions to the post as you edit. You may want to increase this setting for longer delays in between auto-saves, or decrease the setting to make sure you never lose changes.
 * @since 2.5.0 */
!defined( &#039;AUTOSAVE_INTERVAL&#039; ) &amp;&amp; define( &#039;AUTOSAVE_INTERVAL&#039;, 60 );
&nbsp;
/** @since 2.9.0  */
/** Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. */
!defined( &#039;EMPTY_TRASH_DAYS&#039; ) &amp;&amp; define( &#039;EMPTY_TRASH_DAYS&#039;, 300 );</pre>
<hr class="C" />
<h2>Debugging WordPress</h2>
<p>One of my secrets for getting really good at this stuff is to master debugging.  There is really not ever a time when I am working on a site that I don&#8217;t have <a href="http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html">color-highlighted logs scrolling automatically in an ssh window</a>.  It&#8217;s really almost impossible to fix problems with wordpress or do any kind of advanced anything without being able to view debugging info.  At first I relied heavily on a <a href="http://www.askapache.com/php/custom-phpini-tips-and-tricks.html">custom php.ini</a> being available on the server, but after having to deal with many hosts who don&#8217;t allow <code>php.ini</code> files I now rely completely on setting values using <a href="http://php.net/manual/en/function.ini-set.php" rel="nofollow" >ini_set</a> for ultimate portability. Detailed towards the end of this article and is also included in this <code>wp-config.php</code></p>
<pre>/**#@+
 * DEBUGGING STUFF
 */
/** display of notices during development. if false, error_reporting is E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR otherwise E_ALL */
!defined(&#039;WP_DEBUG&#039;) &amp;&amp; define(&#039;WP_DEBUG&#039;, false);
&nbsp;
/** The SAVEQUERIES definition saves the database queries to a array and that array can be displayed to help analyze those queries.
 *  The information saves each query, what function called it, and how long that query took to execute.  */
!defined(&#039;SAVE_QUERIES&#039;) &amp;&amp; define(&#039;SAVE_QUERIES&#039;, WP_DEBUG);
&nbsp;
!defined(&#039;ACTION_DEBUG&#039;) &amp;&amp; define(&#039;ACTION_DEBUG&#039;, WP_DEBUG);
&nbsp;
/** This will allow you to edit the scriptname.dev.js files in the wp-includes/js and wp-admin/js directories.  */
!defined(&#039;SCRIPT_DEBUG&#039;) &amp;&amp; define(&#039;SCRIPT_DEBUG&#039;, WP_DEBUG);

&nbsp;
/** Add define(&#039;WP_DEBUG_LOG&#039;, true); to enable php debug logging to WP_CONTENT_DIR/debug.log */
//!defined(&#039;WP_DEBUG_LOG&#039;) &amp;&amp; define(&#039;WP_DEBUG_LOG&#039;, true);
&nbsp;
/** This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
 *  Add define(&#039;WP_DEBUG_DISPLAY&#039;, false); to wp-config.php to use the globally configured setting for display_errors and not force it to On */
!defined(&#039;WP_DEBUG_DISPLAY&#039;) &amp;&amp; define(&#039;WP_DEBUG_DISPLAY&#039;, false);</pre>
<hr class="C" />
<h2>Ultimate Security Tweaks</h2>
<p>Well, ultimate for WP&#8217;s built-in keys and password functions, this is all for wp-config.php keep in mind.  This is a very neccessary and recommended step, and is one of the only things I modify for each new installation.</p>
<h3>Security KEYS</h3>
<p>If like me you are familiar with password-cracking software like John the ripper, rainbow hash tables, l0pht-crack, etc.. then you will like to know that you can specify your own keys and salts for the encryption used by WP.  They are <code>AUTH_KEY</code>, <code>AUTH_SALT</code>, <code>SECURE_AUTH_KEY</code>, <code>SECURE_AUTH_SALT</code>, <code>LOGGED_IN_KEY</code>, <code>LOGGED_IN_SALT</code>, <code>NONCE_KEY</code>, <code>NONCE_SALT</code>, <code>SECRET_KEY</code> and <code>SECRET_SALT</code>.</p>
<p>A random and long key gives you better encryption, and exponentially increasing that is using a random and long salt for the encryption.  Encryptions with known salts are incredibly easy to decrypt compared to encryptions with secure salts, because the salt + key individually need to be guessed in order to find a matching hash, vs. just the key if the salt is known.  See: <a href="http://www.askapache.com/security/locating-weak-passwords.html">Locating weak passwords</a>.</p>
<blockquote>
<p>A secret key is a hashing salt which makes your site harder to hack and access harder to crack by adding random elements to the password.</p>
<p>In simple terms, a secret key is a password with elements that make it harder to generate enough options to break through your security barriers. A password like &#8220;password&#8221; or &#8220;test&#8221; is simple and easily broken. A random, unpredictable password such as &#8220;88a7da62429ba6ad3cb3c76a09641fc&#8221; takes years to come up with the right combination.</p>
</blockquote>
<p>For more information on the technical background and breakdown of secret keys and secure passwords, see: </p>
<ul>
<li><a href="http://wordpress.org/support/topic/170987" rel="nofollow" >WordPress Support Forum &#8211; HOWTO: Set up secret keys in WordPress 2.6+</a></li>
<li><a href="http://en.wikipedia.org/wiki/Password_cracking" rel="nofollow" >Wikipedia&#8217;s explanation of Password Cracking</a></li>
</ul>
<p>I like to use the <a href="https://api.wordpress.org/secret-key/1.1/" rel="nofollow" >WordPress.org secret-key service</a> 4 times.  That&#8217;s because for each key and salt I like to do: (1 key from api +random keyboard input+1 key from api).</p>
<pre>/**#@+
 * Authentication Unique Keys.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 *
 * Get salt to add to hashes to help prevent attacks.
 *
 * The secret key is located in two places: the database in case the secret key
 * isn&#039;t defined in the second place, which is in the wp-config.php file. If you
 * are going to set the secret key, then you must do so in the wp-config.php
 * file.
 *
 * The secret key in the database is randomly generated and will be appended to
 * the secret key that is in wp-config.php file in some instances. It is
 * important to have the secret key defined or changed in wp-config.php.
 *
 * If you have installed WordPress 2.5 or later, then you will have the
 * SECRET_KEY defined in the wp-config.php already. You will want to change the
 * value in it because hackers will know what it is. If you have upgraded to
 * WordPress 2.5 or later version from a version before WordPress 2.5, then you
 * should add the constant to your wp-config.php file.
 *
 * Below is an example of how the SECRET_KEY constant is defined with a value.
 * You must not copy the below example and paste into your wp-config.php. If you
 * need an example, then you can have a
 * {@link https://api.wordpress.org/secret-key/1.1/ secret key created} for you.
 *
 * Salting passwords helps against tools which has stored hashed values of
 * common dictionary strings. The added values makes it harder to crack if given
 * salt string is not weak.
 *
 * @since 2.5
 * @link https://api.wordpress.org/secret-key/1.1/ Create a Secret Key for wp-config.php
 *
 * @return string Salt value from either &#039;SECRET_KEY&#039; or &#039;secret&#039; option
 */
define(&#039;AUTH_KEY&#039;,        &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?p[B+GR{@&gt;{Yq`c|LnG;dvq#| %OA_cbBSU6,rICC1o/c)-|&#039;);
define(&#039;SECURE_AUTH_KEY&#039;, &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[Bb15baar8&amp;R-r&lt;[T|?(xhJJABGq+Ux+U$)-Hltp/&#039;);
define(&#039;LOGGED_IN_KEY&#039;,   &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[B&lt;5n6DG|YWnJ9tY2!M1L)`{-$LW~~Ia%.uCbn!P. 41o2$Z$4&#039;);
define(&#039;NONCE_KEY&#039;,       &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[Bgu&lt;wM*zewR0.{+m:bmrB?wj!B,4]Wo+4 Avk ApR-D?E&#039;);
define(&#039;SECRET_KEY&#039;,     &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[B52ugH6muE9r4._iZwoYKUybrqLPpv|d Xr+|yrqhUE&#039;);
&nbsp;
define(&#039;AUTH_SALT&#039;,        &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdm~Ky%+%~PPa5b YEmDI%U[W!-B&#039;);
define(&#039;SECURE_AUTH_SALT&#039;, &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmad/7o6.AU3%9o-|Kqm]+eUqr-n~:ag&#039;);
define(&#039;LOGGED_IN_SALT&#039;,   &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmsLiCv@KJ{#wd(?qe(KcH3!&#039;);
define(&#039;NONCE_SALT&#039;,       &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmG9&gt;+wm 2)bS0Pd_+1rx0brX]ND8|&#039;);
define(&#039;SECRET_SALT&#039;,      &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdm2&lt;&gt;))U|sty)+4vpWooKls/^[vN&#039;);
/**#@-*/</pre>
<hr class="C" />
<h2>Using SSL for Admin and Login</h2>
<p>SSL is kinda required from my point of view, it is just way to easy to sniff data off the wire otherwise.  At least with SSL you force them to use tools like burpsuite, paros proxy, webscarab, etc..</p>
<pre>/** @since 2.6.0  */
!defined(&#039;FORCE_SSL_ADMIN&#039;) &amp;&amp; define(&#039;FORCE_SSL_ADMIN&#039;, true);
&nbsp;
/** @since 2.6.0  */
!defined(&#039;FORCE_SSL_LOGIN&#039;) &amp;&amp; define(&#039;FORCE_SSL_LOGIN&#039;, true);</pre>
<h3>Mod_Rewrite to Force SSL</h3>
<p>This is pretty cool, it forces non-https for all urls except for /wp-admin and wp-login.php, which both require https.  It also checks for the logged_in_cookie, and if that is present in the request then it doesn't force non-https.  Kinda confusing if you don't have a <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">mod_rewrite cheatsheet</a>.</p>
<pre>RewriteCond %{THE_REQUEST} ^$ [OR]
RewriteCond %{REQUEST_URI} ^/(wp-admin|wp-login\.php).*$ [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*wp_li_sadfsdfasdf11b361cdsdfasdfasd=.*$ [NC]
RewriteRule .* - [S=1]
&nbsp;
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(wp-admin/.*|wp-login\.php.*)\ HTTP/ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre>
<hr class="C" />
<h2>File System Permissions</h2>
<p><a href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html"class="IFR" ><img src="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" alt="chmod, umask, file permissions test" title="chmod, umask, file permissions test" /></a>You can get a basic and solid intro on file permissions by reading: <a href="http://codex.wordpress.org/Changing_File_Permissions" rel="nofollow" >Changing File Permissions</a>, or you can check out some of my <a href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html">file permission research</a>.<br class="C" />
</p>
<pre>/** The permissions as octal number, usually 0644 for files, 0755 for dirs.
 *  http://codex.wordpress.org/Changing_File_Permissions
 *  if ( !$wp_filesystem-&gt;mkdir($remote_destination, FS_CHMOD_DIR) )
 */
!defined(&#039;FS_CHMOD_DIR&#039;) &amp;&amp; define(&#039;FS_CHMOD_DIR&#039;, (0755 &amp; ~ umask()));
!defined(&#039;FS_CHMOD_FILE&#039;) &amp;&amp; define(&#039;FS_CHMOD_FILE&#039;, (0644 &amp; ~ umask()));
/**#@-*/
&nbsp;
/** Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default. */
//stream_set_timeout( $stream, FS_TIMEOUT );
//!defined(&#039;FS_TIMEOUT&#039;) &amp;&amp; define(&#039;FS_TIMEOUT&#039;, 30);
&nbsp;
//$this-&gt;link = @ftp_connect($this-&gt;options[&#039;hostname&#039;], $this-&gt;options[&#039;port&#039;], FS_CONNECT_TIMEOUT);
//!defined(&#039;FS_CONNECT_TIMEOUT&#039;) &amp;&amp; define(&#039;FS_CONNECT_TIMEOUT&#039;, 30);
&nbsp;
// function get_filesystem_method($args = array(), $context = false) {
//  $method = defined(&#039;FS_METHOD&#039;) ? FS_METHOD : false; //Please ensure that this is either &#039;direct&#039;, &#039;ssh&#039;, &#039;ftpext&#039; or &#039;ftpsockets&#039;
//!defined(&#039;FS_METHOD&#039;) &amp;&amp; define(&#039;FS_METHOD&#039;, &#039;direct&#039;);
&nbsp;
/** These methods for the WordPress core, plugin, and theme upgrades try to determine the WordPress path, as reported by PHP, but symlink trickery can sometimes
 * &#039;muck this up&#039; so if you know the paths to the various folders on the server, as seen via your FTP user, you can manually define them in the wp-config.php file.
 * FS_METHOD forces the filesystem method. It should only be &quot;direct&quot;, &quot;ssh&quot;, &quot;ftpext&quot;, or &quot;ftpsockets&quot;.
 * FTP_BASE is the full path to the &quot;base&quot; folder of the WordPress installation.
 * FTP_CONTENT_DIR is the full path to the wp-content folder of the WordPress installation.
 * FTP_PLUGIN_DIR is the full path to the plugins folder of the WordPress installation.
 * FTP_PUBKEY is the full path to your SSH public key.
 * FTP_PRIKEY is the full path to your SSH private key.
 * FTP_USER is either user FTP or SSH username. Most likely these are the same, but use the appropriate one for the type of update you wish to do.
 * FTP_PASS is the password for the username entered for FTP_USER. If you are using SSH public key authentication this can be omitted.
 * FTP_HOST is the hostname:port combination for your SSH/FTP server. The standard FTP port is 21 and the standard SSH port is 22.
 */
//define(&#039;FS_METHOD&#039;, &#039;ftpext&#039;);
//define(&#039;FTP_BASE&#039;, &#039;/path/to/wordpress/&#039;);
//define(&#039;FTP_CONTENT_DIR&#039;, &#039;/path/to/wordpress/wp-content/&#039;);
//define(&#039;FTP_PLUGIN_DIR &#039;, &#039;/path/to/wordpress/wp-content/plugins/&#039;);
//define(&#039;FTP_PUBKEY&#039;, &#039;/home/username/.ssh/id_rsa.pub&#039;);
//define(&#039;FTP_PRIKEY&#039;, &#039;/home/username/.ssh/id_rsa&#039;);
//define(&#039;FTP_USER&#039;, &#039;username&#039;);
//define(&#039;FTP_PASS&#039;, &#039;password&#039;);
//define(&#039;FTP_HOST&#039;, &#039;ftp.example.org:21&#039;);
&nbsp;
/**
 * Block requests through the proxy.
 *
 * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will
 * prevent plugins from working and core functionality, if you don&#039;t include api.wordpress.org.
 *
 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file
 * and this will only allow localhost and your blog to make requests.
 * The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
 *
 * @since 2.8.0
 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
/** @since 2.9  */
//!defined(&#039;WP_HTTP_BLOCK_EXTERNAL&#039;) &amp;&amp; define( &#039;WP_HTTP_BLOCK_EXTERNAL&#039;, false );
&nbsp;
/*
 * The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
 *
 * @since 2.8.0
 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
 * $accessible_hosts = preg_split(&#039;|,\s*|&#039;, WP_ACCESSIBLE_HOSTS);
 * return !in_array( $check[&#039;host&#039;], $accessible_hosts ); //Inverse logic, If its in the array, then we can&#039;t access it.
 */
//!defined(&#039;WP_ACCESSIBLE_HOSTS&#039;) &amp;&amp; define( &#039;WP_ACCESSIBLE_HOSTS&#039;, &#039;askapache.com,askapache.org&#039; );</pre>
<hr class="C" />
<h3>Cookies!</h3>
<p>There&#8217;s always a little comfort in having non-default cookies for security (against auto-bots), and using shorter names also means smaller HTTP Packets.</p>
<p>The <code>$cookie_hash</code> is my hack to get around the fact that <code>COOKIEHASH</code> isn&#8217;t definable in <code>wp-config</code>.</p>
<pre>/**#@+
 * COOKIES
 * Used to guarantee unique hash cookies @since 1.5 */
$cookie_hash=md5(WP_SITEURL);
&nbsp;
/** Set a cookie now to see if they are supported by the browser.
 * setcookie(TEST_COOKIE, &#039;WP Cookie check&#039;, 0, COOKIEPATH, COOKIE_DOMAIN);
 * @since 2.3.0 */
!defined(&#039;TEST_COOKIE&#039;) &amp;&amp; define(&#039;TEST_COOKIE&#039;, &#039;wp_tc&#039;);
&nbsp;
/* @since 2.6.0 */
!defined(&#039;LOGGED_IN_COOKIE&#039;) &amp;&amp; define(&#039;LOGGED_IN_COOKIE&#039;, &#039;wp_li_&#039; . $cookie_hash);
&nbsp;
/* @since 2.6.0 */
!defined(&#039;SECURE_AUTH_COOKIE&#039;) &amp;&amp; define(&#039;SECURE_AUTH_COOKIE&#039;, &#039;wp_sa_&#039; . $cookie_hash);
&nbsp;
/* @since 2.5.0 */
!defined(&#039;AUTH_COOKIE&#039;) &amp;&amp; define(&#039;AUTH_COOKIE&#039;, &#039;wp_a_&#039; . $cookie_hash);
&nbsp;
/* @since 2.0.0 */
!defined(&#039;PASS_COOKIE&#039;) &amp;&amp; define(&#039;PASS_COOKIE&#039;, &#039;wp_p_&#039; . $cookie_hash);
&nbsp;
/* @since 2.0.0 */
!defined(&#039;USER_COOKIE&#039;) &amp;&amp; define(&#039;USER_COOKIE&#039;, &#039;wp_u_&#039; . $cookie_hash);
&nbsp;
/* ok unset this var, its not needed as COOKIEHASH will have this value, but is not definable in wp-config.php */
unset($cookie_hash);
&nbsp;
/** @since 1.2.0 */
!defined(&#039;COOKIEPATH&#039;) &amp;&amp; define(&#039;COOKIEPATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_HOME . &#039;/&#039; ) );
&nbsp;
/** @since 1.5.0 */
!defined(&#039;SITECOOKIEPATH&#039;) &amp;&amp; define(&#039;SITECOOKIEPATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_SITEURL . &#039;/&#039; ) );
&nbsp;
/** @since 2.6.0 */
!defined(&#039;ADMIN_COOKIE_PATH&#039;) &amp;&amp; define( &#039;ADMIN_COOKIE_PATH&#039;, SITECOOKIEPATH . &#039;wp-admin&#039; );
&nbsp;
/** @since 2.6.0 */
!defined(&#039;PLUGINS_COOKIE_PATH&#039;) &amp;&amp; define( &#039;PLUGINS_COOKIE_PATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_PLUGIN_URL)  );
&nbsp;
/** @since 2.0.0 */
!defined(&#039;COOKIE_DOMAIN&#039;) &amp;&amp; define(&#039;COOKIE_DOMAIN&#039;, $_SERVER[&#039;SERVER_NAME&#039;]);</pre>
<hr class="C" />
<pre>/**
  * The WP_CACHE setting, if true, includes the wp-content/advanced-cache.php script, when executing wp-settings.php.
  * For an advanced caching plugin to use, static because you would only want one
  * if ( defined(&#039;WP_CACHE&#039;) )@include WP_CONTENT_DIR . &#039;/advanced-cache.php&#039;;
  */
!defined(&#039;WP_CACHE&#039;) &amp;&amp; define(&#039;WP_CACHE&#039;, true);
&nbsp;
/** WordPress Localized Language, defaults to en_US.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de.mo to wp-content/languages and set WPLANG to &#039;de&#039; to enable German
 * language support. */
!defined(&#039;WPLANG&#039;) &amp;&amp; define (&#039;WPLANG&#039;, &#039;en_US&#039;);
&nbsp;
/** Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR
 *   and uses that folder if it exists. Or it uses the &quot;languages&quot; folder in WPINC. @since 2.1.0 */
//!defined(&#039;WP_LANG_DIR&#039;) &amp;&amp; define(&#039;WP_LANG_DIR&#039;, ABSPATH . WPINC . &#039;/languages&#039;);
&nbsp;
/** LANGDIR defines what directory the WPLANG .mo file resides. If LANGDIR is not defined WordPress looks first to wp-content/languages and then wp-includes/languages for the .mo defined by WPLANG file.  Old static relative path maintained for limited backwards compatibility - won&#039;t work in some cases*/
//!defined(&#039;LANGDIR&#039;) &amp;&amp; define(&#039;LANGDIR&#039;, &#039;wp-content/languages&#039;);
&nbsp;
/** Stores the location of the WordPress directory of functions, classes, and core content. @since 1.0.0 */
//!defined(&#039;WPINC&#039;) &amp;&amp; define(&#039;WPINC&#039;, &#039;wp-includes&#039;);</pre>
<hr class="C" />
<h2>WPMU Stuff</h2>
<p>I personally don&#8217;t use.</p>
<pre>/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined(&#039;WPMU_PLUGIN_DIR&#039;) &amp;&amp; define( &#039;WPMU_PLUGIN_DIR&#039;, WP_CONTENT_DIR . &#039;/mu-plugins&#039; ); // full path, no trailing slash
&nbsp;
/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined(&#039;WPMU_PLUGIN_URL&#039;) &amp;&amp; define( &#039;WPMU_PLUGIN_URL&#039;, WP_CONTENT_URL . &#039;/mu-plugins&#039; ); // full url, no trailing slash
&nbsp;
/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined( &#039;MUPLUGINDIR&#039; ) &amp;&amp; define( &#039;MUPLUGINDIR&#039;, &#039;wp-content/mu-plugins&#039; ); // Relative to ABSPATH.  For back compat.</pre>
<hr class="C" />
<h2>WordPress Database</h2>
<p>This is usually the only thing I have to manually edit when creating a new site, unless I just use the same DB and modify the $table_prefix, (farther down). I run everything I possibly can in UTF-8, but if you don&#8217;t already know alot about character sets, wow it is one of the most confusing things so you may want to save learning about that topic for another day.  Otherwise the following are helpful (<em>and show how confusing character sets are!</em>)</p>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html" rel="nofollow" >Character Sets and Collations MySQL Support</a></li>
<li><a href="http://codex.wordpress.org/Converting_Database_Character_Sets" rel="nofollow" >Converting Database Character Sets</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html" rel="nofollow" >UTF-8 character sets</a> (<a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow" >UTF-8</a>)</li>
</ul>
<p>If you ever setup WP to use the builtin membership features, make sure you learn about the <code>CUSTOM_USER_TABLE</code> and <code>CUSTOM_USER_META_TABLE</code> constants, I&#8217;ve found them very helpful.</p>
<pre>/**#@+
 * MySQL settings
 */
/** The name of the database for WordPress */
define(&#039;DB_NAME&#039;, &#039;askapachewpblog75&#039;);
&nbsp;
/** The username to access the database */
define(&#039;DB_USER&#039;, &#039;askapache245d&#039;);
&nbsp;
/** The password for the username to access the database */
define(&#039;DB_PASSWORD&#039;, &#039;asdfklj2340&#039;);
&nbsp;
/** The hostname to connect to the database at */
define(&#039;DB_HOST&#039;, &#039;mysql.askapache.com&#039;);
&nbsp;
/** The charset of the database */
define(&#039;DB_CHARSET&#039;, &#039;utf8&#039;);
&nbsp;
/** The collation of the database */
define(&#039;DB_COLLATE&#039;, &#039;utf8_general_ci&#039;);</pre>
<hr class="C" />
<h2>$table_prefix</h2>
<p>The <code>$table_prefix</code> is the value placed in the front of your database tables. Change the value if you want to use something other than wp_ for your database prefix. Typically this is changed if you are <a href="http://codex.wordpress.org/Installing_Multiple_Blogs" rel="nofollow" >installing multiple WordPress blogs</a> in the same database, and also for enhanced security.</p>
<p>Its a safe and good idea to change this value pre-installation to add more security to your WordPress blog. Exploits attempted against your WordPress blog by malicious crackers often are built with the premise that your blog uses the prefix wp_, by changing the value you mitigate some attack vectors. </p>
<pre>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = &#039;ar15_&#039;;
&nbsp;
/** CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE are used to designated that the user and usermeta tables normally utilized by WordPress are not used, instead these values/tables are used to store your user information. */
//!defined(&#039;CUSTOM_USER_TABLE&#039;) &amp;&amp; define(&#039;CUSTOM_USER_TABLE&#039;, $table_prefix . &#039;my_users&#039;);
//!defined(&#039;CUSTOM_USER_META_TABLE&#039;) &amp;&amp; define(&#039;CUSTOM_USER_META_TABLE&#039;, $table_prefix . &#039;my_usermeta&#039;);</pre>
<h2>Setup PHP Ini Settings</h2>
<pre>&nbsp;
/** Turns the output of errors on or off, you really never want this on, you should only view errors by reading the log file. */
ini_set(&#039;display_errors&#039;, WP_DEBUG_DISPLAY);
&nbsp;
/** Tells whether script error messages should be logged to the server&#039;s error log or error_log. */
ini_set(&#039;log_errors&#039;, &#039;On&#039;);
&nbsp;
/** http://us.php.net/manual/en/timezones.php */
ini_set(&#039;date.timezone&#039;, &#039;America/Indianapolis&#039;);
&nbsp;
/** Where to log php errors */
ini_set(&#039;error_log&#039;, ASKAPACHE_ROOT . &#039;/logs/php_error.log&#039;);
&nbsp;
/** Set the memory limit, otherwise defaults to &#039;32M&#039; */
ini_set(&#039;memory_limit&#039;, WP_MEMORY_LIMIT);</pre>
<h2>Sessions are slow</h2>
<p>So I only use sessions when I have a specific use&#8230; In this case I need sessions only when one of the tools in the /online-tools/ directory is being used.  And that is for the <a href="http://www.askapache.com/security/php-captcha-anti-spam-example.html">captcha image</a>.  In the future I won&#8217;t ever use sessions.</p>
<pre>if(preg_match( &#039;#^/online-tools/#&#039;,$_SERVER[&#039;REQUEST_URI&#039;])) session_start();</pre>
<h2>Include Custom Files</h2>
<p>Sure you could use the my-hacks.php that WP allows, or you can just stick your functions in your <code>TEMPLATEPATH/functions.php</code> file, but they are executed only after the wp-settings.php file, which may be too late for your file.</p>
<p>In the past I&#8217;ve also used the <a href="http://us2.php.net/manual/en/ini.core.php#ini.auto-prepend-file" rel="nofollow" >auto_prepend_file</a> settings to run my script before anything (index.php) but I ran into some issues on different hosts, and it wasn&#8217;t as portable.</p>
<p>This is useful because you can have a file with globally available functions that you can use in non-WP areas as well as WP areas.  I am moving away from this more and more as I learn more about classes and build plugins instead for portability.</p>
<pre>include_once ASKAPACHE_ROOT . &#039;/includes/myfunctions.inc&#039;;
&nbsp;
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . &#039;wp-settings.php&#039;);
?&gt;</pre>
<h2>Some Useful PHP</h2>
<p>I am constantly trying to make my sites and code more portable, so I am using plugins alot more to accomplish things that I use to do with separate php.  Here are some examples of minimal php.</p>
<pre>add_filter(&quot;the_generator&quot;, create_function(&#039;$a&#039;,&#039;return &quot;&quot;;&#039;));
add_filter(&#039;the_content&#039;, create_function(&#039;$a&#039;, &#039;return ((is_feed())? $a.&quot;&lt;p&gt;&lt;a href=\&quot;&quot;.get_permalink().&quot;\&quot;&gt;&quot;.get_the_title().&quot;&lt;/a&gt; originally appeared on &quot;.get_bloginfo(&quot;name&quot;).&quot;.&lt;/p&gt;&quot; : $a);&#039;), 99999);
add_filter(&#039;excerpt_length&#039;, create_function(&#039;$a&#039;, &#039;return 300;&#039;),99);
add_filter(&#039;excerpt_more&#039;, create_function(&#039;$a&#039;, &#039;return &quot;&amp;hellip;&quot;;&#039;),99);
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo &quot;&lt;link rel=\&quot;pingback\&quot; href=\&quot;&#039;.get_bloginfo(&#039;pingback_url&#039;).&#039;\&quot; /&gt;\n&quot;;&#039;), 95 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo &quot;&lt;link rel=\&quot;schema.rss\&quot; href=\&quot;http://purl.org/rss/1.0/\&quot; /&gt;\n&quot;;&#039;), 96 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo &quot;&lt;link rel=\&quot;schema.rel\&quot; href=\&quot;http://purl.org/vocab/relationship/\&quot; /&gt;\n&quot;;&#039;), 97 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo &quot;&lt;link rel=\&quot;meta\&quot; type=\&quot;application/rdf+xml\&quot; href=\&quot;/foaf.rdf\&quot; /&gt;\n&quot;;&#039;), 98 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo &quot;&lt;link href=\&quot;/favicon.ico\&quot; rel=\&quot;shortcut icon\&quot; type=\&quot;image/x-icon\&quot; /&gt;\n&quot;;&#039;), 99 );</pre>
<h2>Debugging Note</h2>
<p><a href="http://wordpress.org/extend/plugins/askapache-debug-viewer/screenshots/" rel="nofollow" ><img alt="AskApache Advanced Debugging Output" src="http://s.wordpress.org/extend/plugins/askapache-debug-viewer/screenshot-1.png?r=160129" title="AskApache Advanced Debugging Output" width="625" height="548" /></a>If you read this far than you probably know how important debugging is, but I sometimes like to stick the best tips deep in my articles to make sure only YOU find it.  GRTFM isn&#8217;t used on this site, it&#8217;s mostly a requirement because my writing can get pretty bad..  The point, debugging is more than a crucial requirement if you want to do anything cool.  Don&#8217;t worry I got you.. check my <a href="http://wordpress.org/extend/plugins/askapache-debug-viewer/" rel="nofollow" >AskApache Debug Viewer Plugin from the official WP site</a>.  It&#8217;s pretty close to providing as verbose amount of information that I could possibly figure out how to get out of php, probably more than you have ever seen at least, I focused on quantity.  I use it all the time on new installs as there is no setup required and it tells me advanced information about the setup of the server, hacker code for sure.<br class="C" />
</p>
<p>Here&#8217;s a quick function to see set global vars, I just think this is interesting code.</p>
<pre>function askapache_global_debug(){
  global $_GET,$_POST,$_COOKIE,$_SESSION,$_ENV,$_FILES,$_SERVER,$_REQUEST,$HTTP_POST_FILES,$HTTP_POST_VARS,$HTTP_SERVER_VARS,$HTTP_RAW_POST_DATA,$HTTP_GET_VARS,$HTTP_COOKIE_VARS,$HTTP_ENV_VARS;
  $gv=create_function(&#039;$n&#039;,&#039;global $$n; ob_start(); if ( is_array($$n) &amp;&amp; sizeof($$n)&gt;0 &amp;&amp; print(&quot;[{$n}]\n&quot;) ) print_r($$n);return ob_get_clean();&#039;);
  foreach (array(&#039;_GET&#039;,&#039;_POST&#039;,&#039;_COOKIE&#039;,&#039;_SESSION&#039;,&#039;_ENV&#039;,&#039;_FILES&#039;,&#039;_SERVER&#039;,&#039;_REQUEST&#039;,&#039;HTTP_POST_FILES&#039;,&#039;HTTP_POST_VARS&#039;,&#039;HTTP_SERVER_VARS&#039;,&#039;HTTP_RAW_POST_DATA&#039;,&#039;HTTP_GET_VARS&#039;,&#039;HTTP_COOKIE_VARS&#039;,&#039;HTTP_ENV_VARS&#039;) as $k)echo $gv($k);
  print_r(get_defined_constants());
}</pre>
<p class="anote">Also check the WordPress Codex page: <a href="http://codex.wordpress.org/Editing_wp-config.php" rel="nofollow" >Editing wp-config.php</a> and Perishable Press&#8217;s: <a href="http://perishablepress.com/press/2009/12/01/stupid-wordpress-tricks/" rel="nofollow" >Stupid WordPress Tricks</a></p>
<p><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html"></a><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html">Advanced WordPress wp-config.php Tweaks</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Optimize a Website for Speed, Security, and Easy Management</title>
		<link>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html</link>
		<comments>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 00:45:26 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[apache server]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[bleeding edge]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[expires header]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Error]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTP Status Codes]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[optimizations]]></category>
		<category><![CDATA[optimized website]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[real deal]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[search and replace]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server config]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trial and error]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1380</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html" class="IFL hs hs37" title="Discover how to setup and manage a website from top to bottom for optimized speed, security, and simplicity"></a>Learn how to setup, configure, secure, optimize, and create a low-maintenance website the AskApache way.  I'm piecing together all the hacks, tricks, methods, and ideas discussed throughout this blog and all across Netdom and glueing them all together to show you how to have the most optimized, crazy fastest, and best website setup I can think of.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><img class="IFL" src="http://uploads.askapache.com/2008/09/computerimg.jpg" alt="optimized server setup" title="optimized server setup" />Over the past 10 or so years I&#8217;ve been directly or indirectly involved in configuring/administrating/hacking thousands of websites, and I realized today that I&#8217;ve actually learned quite a bit about how to really make them work hard for me, instead of the other way around. It came as a mild shock to think of where I was back then vs. now because the improvements and optimizations are hundreds of smaller improvements, but taken together, the  optimization hacks I&#8217;ve found through trial and error and much reading are as Donald would say, <strong>YOOUUGE</strong> compared to a basic website setup.<br class="C" /></p>
<p class="cnote">I use this awesome skeleton setup for all my high-paying clients <em>sorry poor people!</em> and also of course on this blog, which I use as a bleeding-edge dev server for my crazy testing.  So realize that I&#8217;m already past this setup and using it to do cooler stuff.  In order for you to use these more advanced ideas, you first need to get up to speed on what I&#8217;m doing so you know what I&#8217;m talking about.  This article tries to help you accomplish that&#8230; remains to be seen.</p>
<h2>An Optimized Website, The Real Deal</h2>
<p>This first article is to give you some ideas and get you thinking and reading before the first article in this series comes out.  This series details how to setup, configure, secure, optimize, and manage a website the best possible way I can come up with.  It pieces together all the AskApache hacks and tricks and uses methods and ideas discussed all over this blog and all over the net and glues them all together to show you how to have the most optimized, fastest, best website setup I can think of.</p>
<p>Knowing the why and how behind the operation of a Web Server allows us to optimize that operation.  For this example we will be creating the website <code>www.askapache.com</code>, which will be running WordPress and php.  We will also set up <code>static.askapache.com</code> to serve all of our sites uploads, images, css and javascript files, flash files, etc. with advanced caching and security using Apache Server .htaccess files.  So lets get started and take a look at this site structure for a moment.</p>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|&#45;- /home/askapache.com/inc/
|&#45;- /home/askapache.com/logs/
|&#45;- /home/askapache.com/static/
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<ul>
<li><code>/backups/</code> &#8211; For <a href="http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html">encrypted backups of WordPress database and site files</a>. And any other backups.</li>
<li><code>/public_html/</code> &#8211; The document root for <code>www.askapache.com</code></li>
<li><code>/inc/</code> &#8211; Folder to keep your php include files for extra security and easy management.</li>
<li><code>/logs/</code> &#8211; Save your php, apache, and other logs here or create symlinks to them.</li>
<li><code>/static/</code> &#8211; The document root for <code>static.askapache.com</code></li>
<li><code>/tmp/</code> &#8211; Only need this if your host doesn&#8217;t already have a /tmp folder</li>
</ul>
<hr class="HR0" />
<h2>Strong Security, Top to Bottom</h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/1023103_warning_icon_32.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="Site Security with Apache" />Simply by implementing correct access permissions, file permissions, password protection and segmenting various folders and services we are already ahead of the game.  I&#8217;ve always taken security extremely seriously, so you can benefit from alot of the simple solutions I&#8217;m recommending for a really locked down site.<br class="C" /></p>
<p>Indeed, security is a major part of every step of this setup process, as security concerns are what drives a lot of the motivations I have for coming up with this setup in the first place.  We will be doing very simple but very effective site security like the following items, which is a short list compared to everything we will be doing.</p>
<ul>
<li>Fixing file permissions automatically</li>
<li>Searching for modified files on the server</li>
<li>Encrypting your backups</li>
<li>Get alerted to breakin attempts</li>
<li>Block tons of bad clients</li>
<li>Disallowing cgi scripts or any other handlers, just serve files.</li>
<li>Configuring PHP</li>
<li>Password Protection for certain areas</li>
</ul>
<h3>Ready for Warfare?</h3>
<p>My past work for an Internet Service Provider, followed by 4 years of auditing the security of organizations external/internal networks has given me a fresh perspective on website security, and I think it allows me to see what would really be effective at preventing and killing attacks.  In fact just last night I was once again doing some research into some off-the-wall security topics, and I discovered a new defense method that I will be writing about very soon.  I believe that this new method,  could be quickly adopted and implemented by hosting providers and software developers, which would result in us finally taking the Internet back from all those zombies and robots.  This method will be discussed in great detail soon, and will be a core part of this site setups security and optimization.</p>
<hr class="HR0" />
<h2>Built to <span style="color:red">Bleed Speed</span></h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/speedontheroadimg.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="326255_speed_on_the_road" />Serve&#8217;s files as fast and efficiently as possible using advanced caching, HTTP Protocols, php/server configurations.<br class="C" /></p>
<p>Many of the articles and research on this blog is about improving the speed and efficiency of your website.  In fact that is why I am helping develop open-source software to block spammers from WordPress blogs&#8230; not because I&#8217;m bothered by the spam, but because they make the net slow!  So lets look at some of the ideas we&#8217;ll be implementing.</p>
<p>Many techniques I&#8217;ve been using and tweaking for several years, and recently many of them were included in the high-performance websites list.  Of course we will be taking a look at this list in practical terms, meaning almost all of it, the caching, compression, etc., will be automated in keeping with our &#8220;comfort&#8221; goal, which is to say we want to make the Web Developer and Server Admin&#8217;s lives as easy and comfy as possible.  After all, we do the work right?</p>
<ol>
<li>Reduce HTTP requests &#8211; <a href="http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html" title="304 If Modified article">Reducing 304 requests with Cache-Control Headers</a></li>
<li>Use a customized php.ini &#8211; <a href="http://www.askapache.com/php/custom-phpini-tips-and-tricks.html">Creating and using a custom PHP.ini</a></li>
<li>Add an Expires header &#8211; <a href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html#caching-with-mod_expires" title="mod_expires Caching article">Caching with mod_expires on Apache</a></li>
<li>Gzip components</li>
<li>Make CSS and unobtrusive Javascript as external files not inline</li>
<li>Reduce DNS lookups &#8211; Use Static IP address, use a subdomain with static IP address for static content.</li>
<li>Minimize Javascript &#8211; Refactor the code, compress with <a href="http://dojotoolkit.org/docs/shrinksafe" rel="nofollow" >dojo</a></li>
<li>Avoid external redirects &#8211; <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" title="mod_rewrite internal redirection and rewrites">Use internal redirection with mod_rewrite</a>, <a href="http://www.askapache.com/htaccess/301-redirect-with-mod_rewrite-or-redirectmatch.html" title="301 Redirect with mod_rewrite or RedirectMatch">The correct way to redirect with 301</a></li>
<li>Turn off ETags &#8211; <a href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess">Prevent Caching with htaccess</a></li>
<li>Make AJAX cacheable and small</li>
</ol>
<h3>AskApache.com, Fastest Site Ever!</h3>
<p>Ok it <em>might</em> not be the #1, but surely the top 10.. ;)</p>
<p>I&#8217;m very proud of the performance I am able to achieve on this site.  Very proud.  I started looking for ways to improve the wp-cache and wp-super-cache WordPress plugins, and came up with hacks for both of them.. but they still didn&#8217;t do what I wanted so I started from scratch and wrote my own caching plugin.</p>
<p>With much more advanced caching options and unquestionably higher performance and lower time usage on the machine.  I&#8217;m hesitant to release it to the public until I get faded on it.. I just really love it.. it has been running my site for several months now and I keep finding ways to improve it.. Stay tuned.</p>
<p>One feature it has is the ability to allow negotiation of a resource between apache and the client.  Think almost transparent mutli-lingual blogs, mutliple formats per document (look at the rdf for this page for an example*). But that plugin is the future and this is the present.. so back to it we go.</p>
<hr class="HR0" />
<h2>Pamper the Webmaster with Extreme Comfort</h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/wwwonthebeachimg.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="Low Maintenance Web Development" />This section alone would make this setup appealing.  I have developed all types of techniques and methods to make my life as easy as possible.  I could literally DIE right now and this blog would continue to run and operate for years on its own.   The general philosophy that I have used to get to where I can goto the beach with my laptop and do all this crazy stuff is <strong>the idea of perfection</strong>.  That may sound a little put-offish, but it basically means I will focus in on one very specific area for improvement or research and just get sick with it.  Most of this blogs articles are enlightening examples of this in action.  I will take a relatively unknown or unused piece of code or software and experiment with it until I feel I have it down, then I move on to the next item of never-ending research.  Mostly I think this is just plain habit from when I was studying security.  I&#8217;m much better at this then that :)</p>
<h3>Apache ErrorDocuments</h3>
<p>The <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">57 HTTP Status Codes and Apache ErrorDocuments</a> article is a prime example.  I was simply searching for an authoritative list of HTTP status codes, an issue not many web people find worth their time, and that search led to some of the most useful stuff I&#8217;ve found about the Web</p>
<p>This &#8220;Comfort&#8221; article will include multi-language, intelligent, and optimized error documents for handling any type of HTTP error with class and allow us to stop spammers, save bandwidth, redirect correctly, etc..  You will probably be surprised at all the uses an Apache ErrorDocument can have.. It IS one of the foundations of the HTTP-based Net after all.<br class="C" /></p>
<h3>Emphasis on Easy Upgrades</h3>
<p>The whole setup is geared to make hassle-free WordPress/PHP/application upgrades possible by keeping different types of files in separate places, keeping backups, other misc tricks and since all of these files are in /home/askapache.com, your FTP connection can still access every file easily.  Sometimes security and optimizing your server can lead to it being more of a pain to do updates, backups, and general maintenance.  This article tries to overwhelm the balance with a trifecta of goals.</p>
<h3>Move to a new host? Ok!</h3>
<p>Comfort to me also means being able to pack up the whole website and database and move to another web host in under an hour.  I can move the whole AskApache site to one of several other hosting providers accounts I have in about 30minutes.  If this was a clients site or I was getting paid more, I&#8217;d also be focused on round-robin DNS technology, balance-load setups, and just go crazy making it fast.</p>
<h3>Staying Online, Improving Uptime</h3>
<p>Ever since I started sharing information and software to stop all these resource hogging zombies attacking everything I&#8217;ve been attacked several times.  Normally I get over 10K exploit attempts or requests per day, which I pretty much block 100%.  But a few times they&#8217;ve actually tried to DDOS me off the net in a distributed attack.  I have implemented several &#8220;poor mans&#8221; techniques to put up your best effort at surviving, which I did.  Basically you want to configure your server to KILL connections just as fast as possible and prevent your server resources from skyrocketing and surpassing your quotas.  A skilled attacker could easily shut you down even without the use of a widespread botnet if they are clever, which could be devastating to your small blog or site if it goes down at a crucial instant.</p>
<hr class="HR0" />
<h2>Organization with Templates and Systems</h2>
<p>I used to work with a guy who did alot of the coldfusion programming for us, and I used to cringe every  time I was called in to upgrade a site or do a re-design.  Files and folders EVERYWHERE!  Literally images in every folder, multiple index.html, index1.html, index-old.html, and on and on it went.. It would take me hours just to reverse-engineer the site enough so I could modify files on it without having some unkown consequence happen.</p>
<h3>Do You Have a Cluttered Desktop?</h3>
<p>Everyone has this problem, what I do all the time is just grab everything on my desktop and put it in a folder named with the date.  Then the process repeats itself and invariably a few months later I&#8217;m looking at a cluttered screen again.</p>
<p>This absolutely is the worst thing that can happen to a website, worst for security, comfort for webmaster, and speed.  So this setup addresses that issue completely heads on.  With all the different pages, tools, and resources available on this blog, I can almost promise you that my site has less files than yours.  No small feat to be sure, but worth every second I spent researching how to do it now that its on and popping.</p>
<hr class="HR0" />
<h2>What&#8217;s a Website really?</h2>
<p>All hosts are different, but any host worth their salt is running some kind of <a href="http://www.askapache.com/linux-unix/">BSD/Linux</a> operating system, and that is good news because those operating systems all use very similarly excellent file/folder structures with huge organization systems.  If your web hosting provider is running on a Windows based operating system or other locked/proprietary software than this article is not for you and I would recommend switching hosts to a BSD/Linux open-source operating system.</p>
<h3>Listening for Requests with Web Hosting and DNS</h3>
<p>First you set your website up so it can start serving.</p>
<ol>
<li>You buy your domain name, which just gives you the right to use it.</li>
<li>You pay your webhost for an account on their machine running a Server connected to the Net <em>via a fast connection link</em>.</li>
<li>You pay a DNS provider to redirect requests for your domain  name to be sent to your webhosts machine running the server.</li>
</ol>
<h2>Sub-Domain for Serving Assets</h2>
<p>This is a very cool method I&#8217;ve been using more and more frequently because it makes updates, upgrades, and changes so much easier to manage.  And segmenting various parts of the site is smart security, and even smarter in the way of speeding up a website and keeping your <strong>servers running mean and lean</strong>.</p>
<h2>Full Site Structure Expanded</h2>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|   |&#45;- /home/askapache.com/public_html/about/
|   |&#45;- /home/askapache.com/public_html/admin/
|   |&#45;- /home/askapache.com/public_html/cgi-bin/
|   |&#45;- /home/askapache.com/public_html/.htaccess
|   |&#45;- /home/askapache.com/public_html/index.php
|   `&#45;- /home/askapache.com/public_html/robots.txt
|&#45;- /home/askapache.com/inc/
|   |&#45;- /home/askapache.com/inc/config.inc.php
|   `&#45;- /home/askapache.com/inc/settings.inc.php
|&#45;- /home/askapache.com/logs/
|   |&#45;- /home/askapache.com/logs/access.log
|   |&#45;- /home/askapache.com/logs/error.log
|   |&#45;- /home/askapache.com/logs/logins.log
|   |&#45;- /home/askapache.com/logs/modsec_audit.log
|   |&#45;- /home/askapache.com/logs/modsec_debug.log
|   `&#45;- /home/askapache.com/logs/php_error.log
|&#45;- /home/askapache.com/static/
|   |&#45;- /home/askapache.com/static/css/
|   |&#45;- /home/askapache.com/static/flv/
|   |&#45;- /home/askapache.com/static/img/
|   |&#45;- /home/askapache.com/static/js/
|   |&#45;- /home/askapache.com/static/mp3/
|   |&#45;- /home/askapache.com/static/pdf/
|   |&#45;- /home/askapache.com/static/swf/
|   |&#45;- /home/askapache.com/static/.htaccess
|   |&#45;- /home/askapache.com/static/index.html
|   `&#45;- /home/askapache.com/static/robots.txt
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<h2>Full Expanded Structure</h2>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|   |&#45;- /home/askapache.com/public_html/about/
|   |   `&#45;- /home/askapache.com/public_html/about/index.html
|   |&#45;- /home/askapache.com/public_html/admin/
|   |   |&#45;- /home/askapache.com/public_html/admin/.htaccess
|   |   `&#45;- /home/askapache.com/public_html/admin/index.html
|   |&#45;- /home/askapache.com/public_html/cgi-bin/
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/.htaccess
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php.cgi*
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php.ini
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php4.cgi*
|   |   |   `&#45;- /home/askapache.com/public_html/cgi-bin/bin/php5.cgi*
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/.htaccess
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/debug.php
|   |   |   `&#45;- /home/askapache.com/public_html/cgi-bin/private/stats.php
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/.htaccess
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/login.php
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/printenv.cgi*
&nbsp;
|   |   `&#45;- /home/askapache.com/public_html/cgi-bin/redir.cgi*
|   |&#45;- /home/askapache.com/public_html/.htaccess
|   |&#45;- /home/askapache.com/public_html/index.php
|   `&#45;- /home/askapache.com/public_html/robots.txt
|&#45;- /home/askapache.com/inc/
|   |&#45;- /home/askapache.com/inc/config.php
|   `&#45;- /home/askapache.com/inc/functions.php
|&#45;- /home/askapache.com/logs/
|   |&#45;- /home/askapache.com/logs/access.log
|   |&#45;- /home/askapache.com/logs/error.log
|   |&#45;- /home/askapache.com/logs/logins.log
|   |&#45;- /home/askapache.com/logs/modsec_audit.log
|   |&#45;- /home/askapache.com/logs/modsec_debug.log
|   `&#45;- /home/askapache.com/logs/php_error.log
|&#45;- /home/askapache.com/static/
|   |&#45;- /home/askapache.com/static/css/
|   |   `&#45;- /home/askapache.com/static/css/apache.css
|   |&#45;- /home/askapache.com/static/flv/
|   |   `&#45;- /home/askapache.com/static/flv/apache.flv
|   |&#45;- /home/askapache.com/static/img/
|   |   |&#45;- /home/askapache.com/static/img/apache.gif
|   |   |&#45;- /home/askapache.com/static/img/apache.jpg
|   |   `&#45;- /home/askapache.com/static/img/apache.png
|   |&#45;- /home/askapache.com/static/js/
|   |   `&#45;- /home/askapache.com/static/js/apache.js
|   |&#45;- /home/askapache.com/static/mp3/
|   |   `&#45;- /home/askapache.com/static/mp3/apache.mp3
|   |&#45;- /home/askapache.com/static/pdf/
|   |   `&#45;- /home/askapache.com/static/pdf/apache.pdf
|   |&#45;- /home/askapache.com/static/swf/
|   |   `&#45;- /home/askapache.com/static/swf/apache.swf
|   |&#45;- /home/askapache.com/static/.htaccess
|   |&#45;- /home/askapache.com/static/index.html
|   `&#45;- /home/askapache.com/static/robots.txt
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<p>The buzz about apache and open-source is very real, apache is becoming more of a discussed topic as people realize the power and importance of <q cite="LL Cool J">Doing it and Doing it and Doing it well.</q> &#8211;  <small><a href="http://www.webmonkey.com/blog/Jumpbox_Offers_an_Easier_Way_to_Install_Movable_Type" rel="nofollow" >Movable Type Apache Installs made easy</a>, <a href="http://www.ubuntugeek.com/webalizer-apache-web-server-log-file-analysis-tool.html" rel="nofollow" >Checking out Apache Web logs</a>, <a href="http://eventurebiz.com/blog/securing-securing-your-wordpress-blog-post-6-protecting-the-wp-configphp-file/" rel="nofollow" >Securing WordPress with .htaccess</a>, <a href="http://marketingdefined.com/blog/wordpress/using-wordpress-permalink-redirect-plugins-correctly/" rel="nofollow" >WordPress Permalinks and .htaccess</a>, <a href="http://corpocrat.com/2008/09/19/install-apache-mod_substitute/" rel="nofollow" >New search and replace module for apache!</a>, <a href="http://www.csskarma.com/blog/creating-an-htaccess-template/" rel="nofollow" >creating an .htaccess template</a>, <a href="http://www.thelinuxblog.com/htaccess-allow-from/" rel="nofollow" >.htaccess allow directive</a></small></p>
<p class="anote">Check back in a week for the first article, or better yet subscribe to my <a href="http://www.askapache.com/feed/">rss feed</a> or use the comment form below to get notified.</p>
<p><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html"></a><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html">Optimize a Website for Speed, Security, and Easy Management</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>HTTP Status Codes and .htaccess ErrorDocuments</title>
		<link>http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html</link>
		<comments>http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#comments</comments>
		<pubDate>Mon, 04 Jan 2010 20:56:15 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Modules]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WiredTree]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[302 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[503]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTTP Error]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTP Status Codes]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[If-Modified-Since]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[phpBB]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Request Method]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Sniffing]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Wget]]></category>
		<category><![CDATA[Wireshark]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com.com/htaccess/wow-i-served-a-page-for-every-single-http-status-code-and-saved-headers-and-content.html</guid>
		<description><![CDATA[<p>There are a total of <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#apache-response-codes-57">57 HTTP Status Codes</a> recognized by the Apache Web Server.  Wouldn't you like to see what all those headers and their output, ErrorDocuments look like?</p>]]></description>
			<content:encoded><![CDATA[<p><strong>I was trying to find an official, authoritative list of HTTP Status Codes</strong> but I kept finding lists that weren&#8217;t authoritative or complete. So I searched and found my answer in the Apache HTTP Server source code.  Once I had the exact HTTP Status Codes and resulting Error Documents sent by Apache, I researched deeper into HTTP Status Codes by reading as many related RFC&#8217;s as I could find, and several other software source codes were explored.  This is the most authoritative list I know of, if you can do better leave a comment and I&#8217;ll update it.  Another thing to keep in mind, the Status code number itself is what is used by software and hardware to make determinations, the phrase returned by the status code is for the human only and does not have any weight other than informing the user.. So &#8220;503 Service Unavailable&#8221;, &#8220;503 Service Temporarily Unavailable&#8221;, and &#8220;503 Get the heck outta here&#8221; are all completely valid.</p>
<p class="bnote"><strong>Update March 9, 2009</strong>: A lot of sites on the web have updated their HTTP status code lists to include the HTTP Status codes listed on this page, including Wikipedia, IANA, W3C, and others, so rest assured this info is accurate and complete.  If you&#8217;d like to see how to create custom error pages for all of these errors like mine  <a href="http://www.askapache.com/show-error-506">/show-error-506</a> , then check out  <a href="http://www.askapache.com/htaccess/advanced-htaccess-ssi.html">this detailed tutorial</a>  I just posted.</p>
<h2>Contents</h2>
<ul>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#apache-response-codes-57">List of All 57 HTTP Response Status Code</a> </li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#quick-start">Quick Start to triggering ErrorDocuments for each Status Code</a> </li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#automating-the-process">Automate the ErrorDocument Triggering</a>
<ul>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#redirect-code-in-htaccess">The htaccess Code</a> </li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#php-header-grabber-script">PHP script that gets and outputs the Headers/Content</a> </li>
</ul>
</li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#headers-returned-content">Headers and Content Returned</a> </li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#apache-source-code">Apache Source Code</a>
<ul>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#httpdh-h">httpd.h</a> </li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#http_protocol-c">http_protocol.c</a> </li>
</ul>
</li>
</ul>
<h2> <a href="#apache-response-codes-57" rel="nofollow"  name="apache-response-codes-57" id="apache-response-codes-57">57 APACHE HTTP STATUS RESPONSE CODES</a> </h2>
<p>Once I compiled the list of Apache recognized HTTP Status Codes, I was dying to see them all in action (<em>i.e. the corresponding <strong>ErrorDocument</strong></em>).  At first I thought I would have to create a php or perl script emulating each of the 57 HTTP Status Codes, a tedious undertaking I wasn&#8217;t about to do.  Instead I &#8220;asked Apache&#8221; by searching the  <a href="http://httpd.apache.org/docs/trunk/" rel="nofollow" >Apache HTTP Documentation</a>  for <em>ambiguity sending Status Codes and/or triggering ErrorDocuments</em> with an Apache Directive.<br /><strong>While reading</strong> up on  <a href="http://askapache.info/trunk/mod/mod_alias.html" rel="nofollow" >mod_alias</a>  and the  <a href="http://askapache.info/trunk/mod/mod_alias.html#redirect" rel="nofollow" >Redirect</a>  directive I found:</p>
<blockquote cite="http://httpd.apache.org/docs/trunk/mod/mod_alias.html#redirect"><p><cite>Apache Docs</cite></p>
<p>Syntax: <strong>Redirect [status] URL-path URL</strong> The status argument can be used to return <strong>other</strong> HTTP status codes. <strong>Other</strong> status codes can be returned by giving the numeric status code as the value of status.  If the status is between 300 and 399, the URL argument must be present, otherwise it must be omitted.</p>
</blockquote>
<dl>
<dt><a id="code-100" title="Continue">100 Continue</a> </dt>
<dd><a href="/e/100/" rel="nofollow" title="ErrorDocument 100" >ErrorDocument Continue</a>  |  <a href="#status-100" rel="nofollow"  title="Sample Continue">Sample 100 Continue</a> <br />This means that the server has received the request headers, and that the client should proceed to send the request body (in case of a request which   needs to be sent; for example, a POST request). If the request body is large, sending it to a server when a request has already been rejected based upon inappropriate headers is inefficient.   To have a server check if the request could be accepted based on the requests headers alone, a client must send Expect: 100-continue as a header in its initial request (see RFC 2616 14.20 Expect header) and check if a 100 Continue status code is received in response before continuing (or receive 417 Expectation Failed and not continue).</dd>
<dt><a id="code-101" title="Switching Protocols">101 Switching Protocols</a> </dt>
<dd><a href="/e/101/" rel="nofollow" title="ErrorDocument 101" >ErrorDocument Switching Protocols</a>  |  <a href="#status-101" rel="nofollow"  title="Sample Switching Protocols">Sample 101 Switching Protocols</a> <br />This means the requester has asked the server to switch protocols and the server is acknowledging that it will do so.[3]</dd>
<dt><a id="code-102" title="Processing">102 Processing</a> </dt>
<dd><a href="/e/102/" rel="nofollow" title="ErrorDocument 102" >ErrorDocument Processing</a>  |  <a href="#status-102" rel="nofollow"  title="Sample Processing">Sample 102 Processing</a> <br />(WebDAV) &#8211; (RFC 2518 )</dd>
<dt><a id="code-200" title="OK">200 OK</a> </dt>
<dd><a href="/e/200/" rel="nofollow" title="ErrorDocument 200" >ErrorDocument OK</a>  |  <a href="#status-200" rel="nofollow"  title="Sample OK">Sample 200 OK</a> <br />Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an   entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.</dd>
<dt><a id="code-201" title="Created">201 Created</a> </dt>
<dd><a href="/e/201/" rel="nofollow" title="ErrorDocument 201" >ErrorDocument Created</a>  |  <a href="#status-201" rel="nofollow"  title="Sample Created">Sample 201 Created</a> <br />The request has been fulfilled and resulted in a new resource being created.</dd>
<dt><a id="code-202" title="Accepted">202 Accepted</a> </dt>
<dd><a href="/e/202/" rel="nofollow" title="ErrorDocument 202" >ErrorDocument Accepted</a>  |  <a href="#status-202" rel="nofollow"  title="Sample Accepted">Sample 202 Accepted</a> <br />The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it   might be disallowed when processing actually takes place.</dd>
<dt><a id="code-203" title="Non-Authoritative Information">203 Non-Authoritative Information</a> </dt>
<dd><a href="/e/203/" rel="nofollow" title="ErrorDocument 203" >ErrorDocument Non-Authoritative Information</a>  |  <a href="#status-203" rel="nofollow"  title="Sample Non-Authoritative Information">Sample 203 Non-Authoritative Information</a> <br />The server successfully processed the request, but is returning information that may be from another source.</dd>
<dt><a id="code-204" title="No Content">204 No Content</a> </dt>
<dd><a href="/e/204/" rel="nofollow" title="ErrorDocument 204" >ErrorDocument No Content</a>  |  <a href="#status-204" rel="nofollow"  title="Sample No Content">Sample 204 No Content</a> <br />The server successfully processed the request, but is not returning any content.</dd>
<dt><a id="code-205" title="Reset Content">205 Reset Content</a> </dt>
<dd><a href="/e/205/" rel="nofollow" title="ErrorDocument 205" >ErrorDocument Reset Content</a>  |  <a href="#status-205" rel="nofollow"  title="Sample Reset Content">Sample 205 Reset Content</a> <br />The server successfully processed the request, but is not returning any content. Unlike a 204 response, this response requires that the requester   reset the document view.</dd>
<dt><a id="code-206" title="Partial Content">206 Partial Content</a> </dt>
<dd><a href="/e/206/" rel="nofollow" title="ErrorDocument 206" >ErrorDocument Partial Content</a>  |  <a href="#status-206" rel="nofollow"  title="Sample Partial Content">Sample 206 Partial Content</a> <br />The server is delivering only part of the resource due to a range header sent by the client. This is used by tools like wget to enable resuming   of interrupted downloads, or split a download into multiple simultaneous streams.</dd>
<dt><a id="code-207" title="Multi-Status">207 Multi-Status</a> </dt>
<dd><a href="/e/207/" rel="nofollow" title="ErrorDocument 207" >ErrorDocument Multi-Status</a>  |  <a href="#status-207" rel="nofollow"  title="Sample Multi-Status">Sample 207 Multi-Status</a> <br />(WebDAV) &#8211; The message body that follows is an XML message and can contain a number of separate response codes, depending on how many sub-requests   were made.</dd>
<dt><a id="code-226" title="IM Used">226 IM Used</a> </dt>
<dd><a href="/e/226/" rel="nofollow" title="ErrorDocument 226" >ErrorDocument IM Used</a>  |  <a href="#status-226" rel="nofollow"  title="Sample IM Used">Sample 226 IM Used</a> <br />The server has fulfilled a GET request for the resource, and the response is a representation of the result of one or more instance-manipulations   applied to the current instance.  The actual current instance might not be available except by combining this response with other previous or future responses, as appropriate for the specific   instance-manipulation(s).</dd>
<dt><a id="code-300" title="Multiple Choices">300 Multiple Choices</a> </dt>
<dd><a href="/e/300/" rel="nofollow" title="ErrorDocument 300" >ErrorDocument Multiple Choices</a>  |  <a href="#status-300" rel="nofollow"  title="Sample Multiple Choices">Sample 300 Multiple Choices</a> <br />Indicates multiple options for the resource that the client may follow. It, for instance, could be used to present different format options for   video, list files with different extensions, or word sense disambiguation.</dd>
<dt><a id="code-301" title="Moved Permanently">301 Moved Permanently</a> </dt>
<dd><a href="/e/301/" rel="nofollow" title="ErrorDocument 301" >ErrorDocument Moved Permanently</a>  |  <a href="#status-301" rel="nofollow"  title="Sample Moved Permanently">Sample 301 Moved Permanently</a> <br />This and all future requests should be directed to the given URI.</dd>
<dt><a id="code-302" title="Found">302 Found</a> </dt>
<dd><a href="/e/302/" rel="nofollow" title="ErrorDocument 302" >ErrorDocument Found</a>  |  <a href="#status-302" rel="nofollow"  title="Sample Found">Sample 302 Found</a> <br />This is the most popular redirect code[citation needed], but also an example of industrial practice contradicting the standard. HTTP/1.0 specification   (RFC 1945 ) required the client to perform a temporary redirect (the original describing phrase was &#8220;Moved Temporarily&#8221;), but popular browsers implemented it as a 303 See Other. Therefore,   HTTP/1.1 added status codes 303 and 307 to disambiguate between the two behaviours. However, the majority of Web applications and frameworks still use the 302 status code as if it were the   303.</dd>
<dt><a id="code-303" title="See Other">303 See Other</a> </dt>
<dd><a href="/e/303/" rel="nofollow" title="ErrorDocument 303" >ErrorDocument See Other</a>  |  <a href="#status-303" rel="nofollow"  title="Sample See Other">Sample 303 See Other</a> <br />The response to the request can be found under another URI using a GET method. When received in response to a PUT, it should be assumed that the   server has received the data and the redirect should be issued with a separate GET message.</dd>
<dt><a id="code-304" title="Not Modified">304 Not Modified</a> </dt>
<dd><a href="/e/304/" rel="nofollow" title="ErrorDocument 304" >ErrorDocument Not Modified</a>  |  <a href="#status-304" rel="nofollow"  title="Sample Not Modified">Sample 304 Not Modified</a> <br />Indicates the resource has not been modified since last requested. Typically, the HTTP client provides a header like the If-Modified-Since header   to provide a time against which to compare. Utilizing this saves bandwidth and reprocessing on both the server and client, as only the header data must be sent and received in comparison to   the entirety of the page being re-processed by the server, then resent using more bandwidth of the server and client.</dd>
<dt><a id="code-305" title="Use Proxy">305 Use Proxy</a> </dt>
<dd><a href="/e/305/" rel="nofollow" title="ErrorDocument 305" >ErrorDocument Use Proxy</a>  |  <a href="#status-305" rel="nofollow"  title="Sample Use Proxy">Sample 305 Use Proxy</a> <br />Many HTTP clients (such as Mozilla[4] and Internet Explorer) do not correctly handle responses with this status code, primarily for security   reasons.</dd>
<dt><a id="code-306" title="Switch Proxy">306 Switch Proxy</a> </dt>
<dd><a href="/e/306/" rel="nofollow" title="ErrorDocument 306" >ErrorDocument Switch Proxy</a>  |  <a href="#status-306" rel="nofollow"  title="Sample Switch Proxy">Sample 306 Switch Proxy</a> <br />No longer used.</dd>
<dt><a id="code-307" title="Temporary Redirect">307 Temporary Redirect</a> </dt>
<dd><a href="/e/307/" rel="nofollow" title="ErrorDocument 307" >ErrorDocument Temporary Redirect</a>  |  <a href="#status-307" rel="nofollow"  title="Sample Temporary Redirect">Sample 307 Temporary Redirect</a> <br />In this occasion, the request should be repeated with another URI, but future requests can still use the original URI. In contrast to 303,   the request method should not be changed when reissuing the original request. For instance, a POST request must be repeated using another POST request.</dd>
<dt><a id="code-400" title="Bad Request">400 Bad Request</a> </dt>
<dd><a href="/e/400/" rel="nofollow" title="ErrorDocument 400" >ErrorDocument Bad Request</a>  |  <a href="#status-400" rel="nofollow"  title="Sample Bad Request">Sample 400 Bad Request</a> <br />The request contains bad syntax or cannot be fulfilled.</dd>
<dt><a id="code-401" title="Unauthorized">401 Unauthorized</a> </dt>
<dd><a href="/e/401/" rel="nofollow" title="ErrorDocument 401" >ErrorDocument Unauthorized</a>  |  <a href="#status-401" rel="nofollow"  title="Sample Unauthorized">Sample 401 Unauthorized</a> <br />Similar to 403 Forbidden, but specifically for use when authentication is possible but has failed or not yet been provided. The response must   include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.</dd>
<dt><a id="code-402" title="Payment Required">402 Payment Required</a> </dt>
<dd><a href="/e/402/" rel="nofollow" title="ErrorDocument 402" >ErrorDocument Payment Required</a>  |  <a href="#status-402" rel="nofollow"  title="Sample Payment Required">Sample 402 Payment Required</a> <br />The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened,   and this code has never been used.</dd>
<dt><a id="code-403" title="Forbidden">403 Forbidden</a> </dt>
<dd><a href="/e/403/" rel="nofollow" title="ErrorDocument 403" >ErrorDocument Forbidden</a>  |  <a href="#status-403" rel="nofollow"  title="Sample Forbidden">Sample 403 Forbidden</a> <br />The request was a legal request, but the server is refusing to respond to it. Unlike a 401 Unauthorized response, authenticating will make no   difference.</dd>
<dt><a id="code-404" title="Not Found">404 Not Found</a> </dt>
<dd><a href="/e/404/" rel="nofollow" title="ErrorDocument 404" >ErrorDocument Not Found</a>  |  <a href="#status-404" rel="nofollow"  title="Sample Not Found">Sample 404 Not Found</a> <br />The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.</dd>
<dt><a id="code-405" title="Method Not Allowed">405 Method Not Allowed</a> </dt>
<dd><a href="/e/405/" rel="nofollow" title="ErrorDocument 405" >ErrorDocument Method Not Allowed</a>  |  <a href="#status-405" rel="nofollow"  title="Sample Method Not Allowed">Sample 405 Method Not Allowed</a> <br />A request was made of a resource using a request method not supported by that resource; for example, using GET on a form which requires data   to be presented via POST, or using PUT on a read-only resource.</dd>
<dt><a id="code-406" title="Not Acceptable">406 Not Acceptable</a> </dt>
<dd><a href="/e/406/" rel="nofollow" title="ErrorDocument 406" >ErrorDocument Not Acceptable</a>  |  <a href="#status-406" rel="nofollow"  title="Sample Not Acceptable">Sample 406 Not Acceptable</a> <br />The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.</dd>
<dt><a id="code-407" title="Proxy Authentication Required">407 Proxy Authentication Required</a> </dt>
<dd><a href="/e/407/" rel="nofollow" title="ErrorDocument 407" >ErrorDocument Proxy Authentication Required</a>  |  <a href="#status-407" rel="nofollow"  title="Sample Proxy Authentication Required">Sample 407 Proxy Authentication Required</a> <br />Required</dd>
<dt><a id="code-408" title="Request Timeout">408 Request Timeout</a> </dt>
<dd><a href="/e/408/" rel="nofollow" title="ErrorDocument 408" >ErrorDocument Request Timeout</a>  |  <a href="#status-408" rel="nofollow"  title="Sample Request Timeout">Sample 408 Request Timeout</a> <br />The server timed out waiting for the request.</dd>
<dt><a id="code-409" title="Conflict">409 Conflict</a> </dt>
<dd><a href="/e/409/" rel="nofollow" title="ErrorDocument 409" >ErrorDocument Conflict</a>  |  <a href="#status-409" rel="nofollow"  title="Sample Conflict">Sample 409 Conflict</a> <br />Indicates that the request could not be processed because of conflict in the request, such as an edit conflict.</dd>
<dt><a id="code-410" title="Gone">410 Gone</a> </dt>
<dd><a href="/e/410/" rel="nofollow" title="ErrorDocument 410" >ErrorDocument Gone</a>  |  <a href="#status-410" rel="nofollow"  title="Sample Gone">Sample 410 Gone</a> <br />Indicates that the resource requested is no longer available and will not be available again. This should be used when a resource has been intentionally   removed; however, it is not necessary to return this code and a 404 Not Found can be issued instead. Upon receiving a 410 status code, the client should not request the resource again in the   future. Clients such as search engines should remove the resource from their indexes.</dd>
<dt><a id="code-411" title="Length Required">411 Length Required</a> </dt>
<dd><a href="/e/411/" rel="nofollow" title="ErrorDocument 411" >ErrorDocument Length Required</a>  |  <a href="#status-411" rel="nofollow"  title="Sample Length Required">Sample 411 Length Required</a> <br />The request did not specify the length of its content, which is required by the requested resource.</dd>
<dt><a id="code-412" title="Precondition Failed">412 Precondition Failed</a> </dt>
<dd><a href="/e/412/" rel="nofollow" title="ErrorDocument 412" >ErrorDocument Precondition Failed</a>  |  <a href="#status-412" rel="nofollow"  title="Sample Precondition Failed">Sample 412 Precondition Failed</a> <br />The server does not meet one of the preconditions that the requester put on the request.</dd>
<dt><a id="code-413" title="Request Entity Too Large">413 Request Entity Too Large</a> </dt>
<dd><a href="/e/413/" rel="nofollow" title="ErrorDocument 413" >ErrorDocument Request Entity Too Large</a>  |  <a href="#status-413" rel="nofollow"  title="Sample Request Entity Too Large">Sample 413 Request Entity Too Large</a> <br />The request is larger than the server is willing or able to process.</dd>
<dt><a id="code-414" title="Request-URI Too Long">414 Request-URI Too Long</a> </dt>
<dd><a href="/e/414/" rel="nofollow" title="ErrorDocument 414" >ErrorDocument Request-URI Too Long</a>  |  <a href="#status-414" rel="nofollow"  title="Sample Request-URI Too Long">Sample 414 Request-URI Too Long</a> <br />The URI provided was too long for the server to process.</dd>
<dt><a id="code-415" title="Unsupported Media Type">415 Unsupported Media Type</a> </dt>
<dd><a href="/e/415/" rel="nofollow" title="ErrorDocument 415" >ErrorDocument Unsupported Media Type</a>  |  <a href="#status-415" rel="nofollow"  title="Sample Unsupported Media Type">Sample 415 Unsupported Media Type</a> <br />The request did not specify any media types that the server or resource supports. For example the client specified that an image resource   should be served as image/svg+xml, but the server cannot find a matching version of the image.</dd>
<dt><a id="code-416" title="Requested Range Not Satisfiable">416 Requested Range Not Satisfiable</a> </dt>
<dd><a href="/e/416/" rel="nofollow" title="ErrorDocument 416" >ErrorDocument Requested Range Not Satisfiable</a>  |  <a href="#status-416" rel="nofollow"  title="Sample Requested Range Not Satisfiable">Sample 416 Requested Range Not Satisfiable</a> <br />The client has asked for a portion of the file, but the server cannot supply that portion (for example, if the client asked for   a part of the file that lies beyond the end of the file).</dd>
<dt><a id="code-417" title="Expectation Failed">417 Expectation Failed</a> </dt>
<dd><a href="/e/417/" rel="nofollow" title="ErrorDocument 417" >ErrorDocument Expectation Failed</a>  |  <a href="#status-417" rel="nofollow"  title="Sample Expectation Failed">Sample 417 Expectation Failed</a> <br />The server cannot meet the requirements of the Expect request-header field.</dd>
<dt><a id="code-418" title="I'm a teapot">418 I&#8217;m a teapot</a> </dt>
<dd><a href="/e/418/" rel="nofollow" title="ErrorDocument 418" >ErrorDocument I&#8217;m a teapot</a>  |  <a href="#status-418" rel="nofollow"  title="Sample I'm a teapot">Sample 418 I&#8217;m a teapot</a> <br />The HTCPCP server is a teapot. The responding entity MAY be short and stout. Defined by the April Fools specification RFC 2324. See Hyper Text   Coffee Pot Control Protocol for more information.</dd>
<dt><a id="code-422" title="Unprocessable Entity">422 Unprocessable Entity</a> </dt>
<dd><a href="/e/422/" rel="nofollow" title="ErrorDocument 422" >ErrorDocument Unprocessable Entity</a>  |  <a href="#status-422" rel="nofollow"  title="Sample Unprocessable Entity">Sample 422 Unprocessable Entity</a> <br />(WebDAV) (RFC 4918 ) &#8211; The request was well-formed but was unable to be followed due to semantic errors.</dd>
<dt><a id="code-423" title="Locked">423 Locked</a> </dt>
<dd><a href="/e/423/" rel="nofollow" title="ErrorDocument 423" >ErrorDocument Locked</a>  |  <a href="#status-423" rel="nofollow"  title="Sample Locked">Sample 423 Locked</a> <br />(WebDAV) (RFC 4918 ) &#8211; The resource that is being accessed is locked</dd>
<dt><a id="code-424" title="Failed Dependency">424 Failed Dependency</a> </dt>
<dd><a href="/e/424/" rel="nofollow" title="ErrorDocument 424" >ErrorDocument Failed Dependency</a>  |  <a href="#status-424" rel="nofollow"  title="Sample Failed Dependency">Sample 424 Failed Dependency</a> <br />(WebDAV) (RFC 4918 ) &#8211; The request failed due to failure of a previous request (e.g. a PROPPATCH).</dd>
<dt><a id="code-425" title="Unordered Collection">425 Unordered Collection</a> </dt>
<dd><a href="/e/425/" rel="nofollow" title="ErrorDocument 425" >ErrorDocument Unordered Collection</a>  |  <a href="#status-425" rel="nofollow"  title="Sample Unordered Collection">Sample 425 Unordered Collection</a> <br />Defined in drafts of WebDav Advanced Collections, but not present in &#8220;Web Distributed Authoring and Versioning (WebDAV) Ordered Collections   Protocol&#8221; (RFC 3648).</dd>
<dt><a id="code-426" title="Upgrade Required">426 Upgrade Required</a> </dt>
<dd><a href="/e/426/" rel="nofollow" title="ErrorDocument 426" >ErrorDocument Upgrade Required</a>  |  <a href="#status-426" rel="nofollow"  title="Sample Upgrade Required">Sample 426 Upgrade Required</a> <br />(RFC 2817 ) &#8211; The client should switch to TLS/1.0.</dd>
<dt><a id="code-449" title="Retry With">449 Retry With</a> </dt>
<dd><a href="/e/449/" rel="nofollow" title="ErrorDocument 449" >ErrorDocument Retry With</a>  |  <a href="#status-449" rel="nofollow"  title="Sample Retry With">Sample 449 Retry With</a> <br />A Microsoft extension. The request should be retried after doing the appropriate action.</dd>
<dt><a id="code-500" title="Internal Server Error">500 Internal Server Error</a> </dt>
<dd><a href="/e/500/" rel="nofollow" title="ErrorDocument 500" >ErrorDocument Internal Server Error</a>  |  <a href="#status-500" rel="nofollow"  title="Sample Internal Server Error">Sample 500 Internal Server Error</a> <br />A generic error message, given when no more specific message is suitable.</dd>
<dt><a id="code-501" title="Not Implemented">501 Not Implemented</a> </dt>
<dd><a href="/e/501/" rel="nofollow" title="ErrorDocument 501" >ErrorDocument Not Implemented</a>  |  <a href="#status-501" rel="nofollow"  title="Sample Not Implemented">Sample 501 Not Implemented</a> <br />The server either does not recognise the request method, or it lacks the ability to fulfil the request.</dd>
<dt><a id="code-502" title="Bad Gateway">502 Bad Gateway</a> </dt>
<dd><a href="/e/502/" rel="nofollow" title="ErrorDocument 502" >ErrorDocument Bad Gateway</a>  |  <a href="#status-502" rel="nofollow"  title="Sample Bad Gateway">Sample 502 Bad Gateway</a> <br />The server was acting as a gateway or proxy and received an invalid response from the upstream server.</dd>
<dt><a id="code-503" title="Service Unavailable">503 Service Unavailable</a> </dt>
<dd><a href="/e/503/" rel="nofollow" title="ErrorDocument 503" >ErrorDocument Service Unavailable</a>  |  <a href="#status-503" rel="nofollow"  title="Sample Service Unavailable">Sample 503 Service Unavailable</a> <br />The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.</dd>
<dt><a id="code-504" title="Gateway Timeout">504 Gateway Timeout</a> </dt>
<dd><a href="/e/504/" rel="nofollow" title="ErrorDocument 504" >ErrorDocument Gateway Timeout</a>  |  <a href="#status-504" rel="nofollow"  title="Sample Gateway Timeout">Sample 504 Gateway Timeout</a> <br />The server was acting as a gateway or proxy and did not receive a timely request from the upstream server.</dd>
<dt><a id="code-505" title="HTTP Version Not Supported">505 HTTP Version Not Supported</a> </dt>
<dd><a href="/e/505/" rel="nofollow" title="ErrorDocument 505" >ErrorDocument HTTP Version Not Supported</a>  |  <a href="#status-505" rel="nofollow"  title="Sample HTTP Version Not Supported">Sample 505 HTTP Version Not Supported</a> <br />The server does not support the HTTP protocol version used in the request.</dd>
<dt><a id="code-506" title="Variant Also Negotiates">506 Variant Also Negotiates</a> </dt>
<dd><a href="/e/506/" rel="nofollow" title="ErrorDocument 506" >ErrorDocument Variant Also Negotiates</a>  |  <a href="#status-506" rel="nofollow"  title="Sample Variant Also Negotiates">Sample 506 Variant Also Negotiates</a> <br />(RFC 2295 ) &#8211; Transparent content negotiation for the request, results in a circular reference.</dd>
<dt><a id="code-507" title="Insufficient Storage">507 Insufficient Storage</a> </dt>
<dd><a href="/e/507/" rel="nofollow" title="ErrorDocument 507" >ErrorDocument Insufficient Storage</a>  |  <a href="#status-507" rel="nofollow"  title="Sample Insufficient Storage">Sample 507 Insufficient Storage</a> <br />(WebDAV) (RFC 4918 )</dd>
<dt><a id="code-509" title="Bandwidth Limit Exceeded">509 Bandwidth Limit Exceeded</a> </dt>
<dd><a href="/e/509/" rel="nofollow" title="ErrorDocument 509" >ErrorDocument Bandwidth Limit Exceeded</a>  |  <a href="#status-509" rel="nofollow"  title="Sample Bandwidth Limit Exceeded">Sample 509 Bandwidth Limit Exceeded</a> <br />(Apache bw/limited extension) &#8211; This status code, while used by many servers, is not specified in any RFCs.</dd>
<dt><a id="code-510" title="Not Extended">510 Not Extended</a> </dt>
<dd><a href="/e/510/" rel="nofollow" title="ErrorDocument 510" >ErrorDocument Not Extended</a>  |  <a href="#status-510" rel="nofollow"  title="Sample Not Extended">Sample 510 Not Extended</a> <br />(RFC 2774 ) &#8211; Further extensions to the request are required for the server to fulfil it.</dd>
</dl>
<h3>1xx Info / Informational</h3>
<p><code>HTTP_INFO</code> &#8211; <strong>Request received, continuing process</strong>. Indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.</p>
<ul>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-100" title="Continue">100</a>  <a href="/e/100/" rel="nofollow" title="ErrorDocument 100" >Continue</a>  &#8211; <code>HTTP_CONTINUE</code></li>
<li> <a href="#status-101" rel="nofollow"  title="Switching Protocols">101</a>  <a href="/e/101/" rel="nofollow" title="ErrorDocument 101" >Switching Protocols</a>  &#8211; <code>HTTP_SWITCHING_PROTOCOLS</code></li>
<li> <a href="#status-102" rel="nofollow"  title="Processing">102</a>  <a href="/e/102/" rel="nofollow" title="ErrorDocument 102" >Processing</a>  &#8211; <code>HTTP_PROCESSING</code></li>
</ul>
<h3>2xx Success / OK</h3>
<p><code>HTTP_SUCCESS</code> &#8211; <strong>The action was successfully received, understood, and accepted</strong>.  Indicates that the client&#8217;s request was successfully received, understood, and accepted.</p>
<ul>
<li> <a href="#status-200" rel="nofollow"  title="OK">200</a>  <a href="/e/200/" rel="nofollow" title="ErrorDocument 200" >OK</a>  &#8211; <code>HTTP_OK</code></li>
<li> <a href="#status-201" rel="nofollow"  title="Created">201</a>  <a href="/e/201/" rel="nofollow" title="ErrorDocument 201" >Created</a>  &#8211; <code>HTTP_CREATED</code></li>
<li> <a href="#status-202" rel="nofollow"  title="Accepted">202</a>  <a href="/e/202/" rel="nofollow" title="ErrorDocument 202" >Accepted</a>  &#8211; <code>HTTP_ACCEPTED</code></li>
<li> <a href="#status-203" rel="nofollow"  title="Non-Authoritative Information">203</a>  <a href="/e/203/" rel="nofollow" title="ErrorDocument 203" >Non-Authoritative Information</a>  &#8211; <code>HTTP_NON_AUTHORITATIVE</code></li>
<li> <a href="#status-204" rel="nofollow"  title="No Content">204</a>  <a href="/e/204/" rel="nofollow" title="ErrorDocument 204" >No Content</a>  &#8211; <code>HTTP_NO_CONTENT</code></li>
<li> <a href="#status-205" rel="nofollow"  title="Reset Content">205</a>  <a href="/e/205/" rel="nofollow" title="ErrorDocument 205" >Reset Content</a>  &#8211; <code>HTTP_RESET_CONTENT</code></li>
<li> <a href="#status-206" rel="nofollow"  title="Partial Content">206</a>  <a href="/e/206/" rel="nofollow" title="ErrorDocument 206" >Partial Content</a>  &#8211; <code>HTTP_PARTIAL_CONTENT</code></li>
<li> <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-207" title="Multi-Status">207</a>  <a href="/e/207/" rel="nofollow" title="ErrorDocument 207" >Multi-Status</a>  &#8211; <code>HTTP_MULTI_STATUS</code></li>
</ul>
<h3>3xx Redirect</h3>
<p><code>HTTP_REDIRECT</code> &#8211; <strong>The client must take additional action to complete the request</strong>.  Indicates that further action needs to be taken by the user-agent in order to fulfill the request. The action required may be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD. A user agent should not automatically <em>redirect a request more than 5 times</em>, since such redirections usually indicate an <strong>infinite loop</strong>.</p>
<ul>
<li> <a href="#status-300" rel="nofollow"  title="Multiple Choices">300</a>  <a href="/e/300/" rel="nofollow" title="ErrorDocument 300" >Multiple Choices</a>  &#8211; <code>HTTP_MULTIPLE_CHOICES</code></li>
<li> <a href="#status-301" rel="nofollow"  title="Moved Permanently">301</a>  <a href="/e/301/" rel="nofollow" title="ErrorDocument 301" >Moved Permanently</a>  &#8211; <code>HTTP_MOVED_PERMANENTLY</code></li>
<li> <a href="#status-302" rel="nofollow"  title="Found">302</a>  <a href="/e/302/" rel="nofollow" title="ErrorDocument 302" >Found</a>  &#8211; <code>HTTP_MOVED_TEMPORARILY</code></li>
<li> <a href="#status-303" rel="nofollow"  title="See Other">303</a>  <a href="/e/303/" rel="nofollow" title="ErrorDocument 303" >See Other</a>  &#8211; <code>HTTP_SEE_OTHER</code></li>
<li> <a href="#status-304" rel="nofollow"  title="Not Modified">304</a>  <a href="/e/304/" rel="nofollow" title="ErrorDocument 304" >Not Modified</a>  &#8211; <code>HTTP_NOT_MODIFIED</code></li>
<li> <a href="#status-305" rel="nofollow"  title="Use Proxy">305</a>  <a href="/e/305/" rel="nofollow" title="ErrorDocument 305" >Use Proxy</a>  &#8211; <code>HTTP_USE_PROXY</code></li>
<li> <a href="#status-306" rel="nofollow"  title="unused">306</a>  <a href="/e/306/" rel="nofollow" title="ErrorDocument 306" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-307" rel="nofollow"  title="Temporary Redirect">307</a>  <a href="/e/307/" rel="nofollow" title="ErrorDocument 307" >Temporary Redirect</a>  &#8211; <code>HTTP_TEMPORARY_REDIRECT</code></li>
</ul>
<h3>4xx Client Error</h3>
<p><code>HTTP_CLIENT_ERROR</code> &#8211; <strong>The request contains bad syntax or cannot be fulfilled</strong>.  Indicates case where client seems to have erred. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition.</p>
<ul>
<li> <a href="#status-400" rel="nofollow"  title="Bad Request">400</a>  <a href="/e/400/" rel="nofollow" title="ErrorDocument 400" >Bad Request</a>  &#8211; <code>HTTP_BAD_REQUEST</code></li>
<li> <a href="#status-401" rel="nofollow"  title="Authorization Required">401</a>  <a href="/e/401/" rel="nofollow" title="ErrorDocument 401" >Authorization Required</a>  &#8211; <code>HTTP_UNAUTHORIZED</code></li>
<li> <a href="#status-402" rel="nofollow"  title="Payment Required">402</a>  <a href="/e/402/" rel="nofollow" title="ErrorDocument 402" >Payment Required</a>  &#8211; <code>HTTP_PAYMENT_REQUIRED</code></li>
<li> <a href="#status-403" rel="nofollow"  title="Forbidden">403</a>  <a href="/e/403/" rel="nofollow" title="ErrorDocument 403" >Forbidden</a>  &#8211; <code>HTTP_FORBIDDEN</code></li>
<li> <a href="#status-404" rel="nofollow"  title="Not Found">404</a>  <a href="/e/404/" rel="nofollow" title="ErrorDocument 404" >Not Found</a>  &#8211; <code>HTTP_NOT_FOUND</code></li>
<li> <a href="#status-405" rel="nofollow"  title="Method Not Allowed">405</a>  <a href="/e/405/" rel="nofollow" title="ErrorDocument 405" >Method Not Allowed</a>  &#8211; <code>HTTP_METHOD_NOT_ALLOWED</code></li>
<li> <a href="#status-406" rel="nofollow"  title="Not Acceptable">406</a>  <a href="/e/406/" rel="nofollow" title="ErrorDocument 406" >Not Acceptable</a>  &#8211; <code>HTTP_NOT_ACCEPTABLE</code></li>
<li> <a href="#status-407" rel="nofollow"  title="Proxy Authentication Required">407</a>  <a href="/e/407/" rel="nofollow" title="ErrorDocument 407" >Proxy Authentication Required</a>  &#8211; <code>HTTP_PROXY_AUTHENTICATION_REQUIRED</code></li>
<li> <a href="#status-408" rel="nofollow"  title="Request Time-out">408</a>  <a href="/e/408/" rel="nofollow" title="ErrorDocument 408" >Request Time-out</a>  &#8211; <code>HTTP_REQUEST_TIME_OUT</code></li>
<li> <a href="#status-409" rel="nofollow"  title="Conflict">409</a>  <a href="/e/409/" rel="nofollow" title="ErrorDocument 409" >Conflict</a>  &#8211; <code>HTTP_CONFLICT</code></li>
<li> <a href="#status-410" rel="nofollow"  title="Gone">410</a>  <a href="/e/410/" rel="nofollow" title="ErrorDocument 410" >Gone</a>  &#8211; <code>HTTP_GONE</code></li>
<li> <a href="#status-411" rel="nofollow"  title="Length Required">411</a>  <a href="/e/411/" rel="nofollow" title="ErrorDocument 411" >Length Required</a>  &#8211; <code>HTTP_LENGTH_REQUIRED</code></li>
<li> <a href="#status-412" rel="nofollow"  title="Precondition Failed">412</a>  <a href="/e/412/" rel="nofollow" title="ErrorDocument 412" >Precondition Failed</a>  &#8211; <code>HTTP_PRECONDITION_FAILED</code></li>
<li> <a href="#status-413" rel="nofollow"  title="Request Entity Too Large">413</a>  <a href="/e/413/" rel="nofollow" title="ErrorDocument 413" >Request Entity Too Large</a>  &#8211; <code>HTTP_REQUEST_ENTITY_TOO_LARGE</code></li>
<li> <a href="#status-414" rel="nofollow"  title="Request-URI Too Large">414</a>  <a href="/e/414/" rel="nofollow" title="ErrorDocument 414" >Request-URI Too Large</a>  &#8211; <code>HTTP_REQUEST_URI_TOO_LARGE</code></li>
<li> <a href="#status-415" rel="nofollow"  title="Unsupported Media Type">415</a>  <a href="/e/415/" rel="nofollow" title="ErrorDocument 415" >Unsupported Media Type</a>  &#8211; <code>HTTP_UNSUPPORTED_MEDIA_TYPE</code></li>
<li> <a href="#status-416" rel="nofollow"  title="Requested Range Not Satisfiable">416</a>  <a href="/e/416/" rel="nofollow" title="ErrorDocument 416" >Requested Range Not Satisfiable</a>  &#8211; <code>HTTP_RANGE_NOT_SATISFIABLE</code></li>
<li> <a href="#status-417" rel="nofollow"  title="Expectation Failed">417</a>  <a href="/e/417/" rel="nofollow" title="ErrorDocument 417" >Expectation Failed</a>  &#8211; <code>HTTP_EXPECTATION_FAILED</code></li>
<li> <a href="#status-418" rel="nofollow"  title="Im a teapot">418</a>  <a href="/e/418/" rel="nofollow" title="ErrorDocument 418" >I&#8217;m a teapot</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-419" rel="nofollow"  title="unused">419</a>  <a href="/e/419/" rel="nofollow" title="ErrorDocument 419" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-420" rel="nofollow"  title="unused">420</a>  <a href="/e/420/" rel="nofollow" title="ErrorDocument 420" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-421" rel="nofollow"  title="unused">421</a>  <a href="/e/421/" rel="nofollow" title="ErrorDocument 421" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-422" rel="nofollow"  title="Unprocessable Entity">422</a>  <a href="/e/422/" rel="nofollow" title="ErrorDocument 422" >Unprocessable Entity</a>  &#8211; <code>HTTP_UNPROCESSABLE_ENTITY</code></li>
<li> <a href="#status-423" rel="nofollow"  title="Locked">423</a>  <a href="/e/423/" rel="nofollow" title="ErrorDocument 423" >Locked</a>  &#8211; <code>HTTP_LOCKED</code></li>
<li> <a href="#status-424" rel="nofollow"  title="Failed Dependency">424</a>  <a href="/e/424/" rel="nofollow" title="ErrorDocument 424" >Failed Dependency</a>  &#8211; <code>HTTP_FAILED_DEPENDENCY</code></li>
<li> <a href="#status-425" rel="nofollow"  title="No code">425</a>  <a href="/e/425/" rel="nofollow" title="ErrorDocument 425" >No code</a>  &#8211; <code>HTTP_NO_CODE</code></li>
<li> <a href="#status-426" rel="nofollow"  title="Upgrade Required">426</a>  <a href="/e/426/" rel="nofollow" title="ErrorDocument 426" >Upgrade Required</a>  &#8211; <code>HTTP_UPGRADE_REQUIRED</code></li>
</ul>
<h3>5xx Server Error</h3>
<p><code>HTTP_SERVER_ERROR</code> &#8211; <strong>The server failed to fulfill an apparently valid request</strong>.  Indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents should display any included entity to the user. These response codes are applicable to any request method.</p>
<ul>
<li> <a href="#status-500" rel="nofollow"  title="Internal Server Error">500</a>  <a href="/e/500/" rel="nofollow" title="ErrorDocument 500" >Internal Server Error</a>  &#8211; <code>HTTP_INTERNAL_SERVER_ERROR</code></li>
<li> <a href="#status-501" rel="nofollow"  title="Method Not Implemented">501</a>  <a href="/e/501/" rel="nofollow" title="ErrorDocument 501" >Method Not Implemented</a>  &#8211; <code>HTTP_NOT_IMPLEMENTED</code></li>
<li> <a href="#status-502" rel="nofollow"  title="Bad Gateway">502</a>  <a href="/e/502/" rel="nofollow" title="ErrorDocument 502" >Bad Gateway</a>  &#8211; <code>HTTP_BAD_GATEWAY</code></li>
<li> <a href="#status-503" rel="nofollow"  title="Service Temporarily Unavailable">503</a>  <a href="/e/503/" rel="nofollow" title="ErrorDocument 503" >Service Temporarily Unavailable</a>  &#8211; <code>HTTP_SERVICE_UNAVAILABLE</code></li>
<li> <a href="#status-504" rel="nofollow"  title="Gateway Time-out">504</a>  <a href="/e/504/" rel="nofollow" title="ErrorDocument 504" >Gateway Time-out</a>  &#8211; <code>HTTP_GATEWAY_TIME_OUT</code></li>
<li> <a href="#status-505" rel="nofollow"  title="HTTP Version Not Supported">505</a>  <a href="/e/505/" rel="nofollow" title="ErrorDocument 505" >HTTP Version Not Supported</a>  &#8211; <code>HTTP_VERSION_NOT_SUPPORTED</code></li>
<li> <a href="#status-506" rel="nofollow"  title="Variant Also Negotiates">506</a>  <a href="/e/506/" rel="nofollow" title="ErrorDocument 506" >Variant Also Negotiates</a>  &#8211; <code>HTTP_VARIANT_ALSO_VARIES</code></li>
<li> <a href="#status-507" rel="nofollow"  title="Insufficient Storage">507</a>  <a href="/e/507/" rel="nofollow" title="ErrorDocument 507" >Insufficient Storage</a>  &#8211; <code>HTTP_INSUFFICIENT_STORAGE</code></li>
<li> <a href="#status-508" rel="nofollow"  title="unused">508</a>  <a href="/e/508/" rel="nofollow" title="ErrorDocument 508" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-509" rel="nofollow"  title="unused">509</a>  <a href="/e/509/" rel="nofollow" title="ErrorDocument 509" >unused</a>  &#8211; <code>UNUSED</code></li>
<li> <a href="#status-510" rel="nofollow"  title="Not Extended">510</a>  <a href="/e/510/" rel="nofollow" title="ErrorDocument 510" >Not Extended</a>  &#8211; <code>HTTP_NOT_EXTENDED</code></li>
</ul>
<hr />
<h2> <a href="#quick-start" rel="nofollow"  name="quick-start" id="quick-start">Quick Start to triggering ErrorDocuments for each Status Code</a> </h2>
<p>Let start with a quick and easy example.  Add the following Redirect rules to your htaccess file, then open your browser and goto each url like <code>yoursite.com/e/400</code>. <em>Don&#8217;t create an /e/ directory or any files.</em></p>
<pre>Redirect 400 /e/400
Redirect 503 /e/503
Redirect 405 /e/405</pre>
<p> <a href="http://uploads.askapache.com/2007/03/error-400s.png" rel="nofollow"  title="Apache ErrorDocument Results" rel="lb"><img src="http://uploads.askapache.com/2007/03/error-400s.thumbnail.png" alt="Apache ErrorDocument Results" title="error 400s.thumbnail apache" /></a> <br /> <a href="http://uploads.askapache.com/2007/03/error-503.png" rel="nofollow"  title="error 503" rel="lb"><img src="http://uploads.askapache.com/2007/03/error-503.thumbnail.png" alt="error 503" title="error 503.thumbnail apache" /></a> </p>
<h2> <a href="#automating-the-process" rel="nofollow"  name="automating-the-process" id="automating-the-process">Automate the ErrorDocument Triggering</a> </h2>
<h3> <a href="#redirect-code-in-htaccess" rel="nofollow"  name="redirect-code-in-htaccess" id="redirect-code-in-htaccess">The htaccess Redirects</a> </h3>
<p>When a Status code is encountered, Apache outputs the Header and the ErrorDocument for that error code.  So you can view any Header and the default ErrorDocument, by causing that numerical error code, which is caused by the Status Code.</p>
<p>For instance, if you request a file that doesn&#8217;t exist, a <strong>404 Not Found</strong> Header is issued and the corresponding ErrorDocument is served with the <strong>404 Not Found</strong> Header.</p>
<pre>Redirect 100 /e/100
Redirect 101 /e/101
Redirect 102 /e/102
Redirect 200 /e/200
Redirect 201 /e/201
Redirect 202 /e/202
Redirect 203 /e/203
Redirect 204 /e/204
Redirect 205 /e/205
Redirect 206 /e/206
Redirect 207 /e/207
Redirect 300 /e/300 http://www.askapache.com/?s=300
Redirect 301 /e/301 http://www.askapache.com/?s=301
Redirect 302 /e/302 http://www.askapache.com/?s=302
Redirect 303 /e/303 http://www.askapache.com/?s=303
Redirect 304 /e/304 http://www.askapache.com/?s=304
Redirect 305 /e/305 http://www.askapache.com/?s=305
Redirect 306 /e/306 http://www.askapache.com/?s=306
Redirect 307 /e/307 http://www.askapache.com/?s=307
Redirect 400 /e/400
Redirect 401 /e/401
Redirect 402 /e/402
Redirect 403 /e/403
Redirect 404 /e/404
Redirect 405 /e/405
Redirect 406 /e/406
Redirect 407 /e/407
Redirect 408 /e/408
Redirect 409 /e/409
Redirect 410 /e/410
Redirect 411 /e/411
Redirect 412 /e/412
Redirect 413 /e/413
Redirect 414 /e/414
Redirect 415 /e/415
Redirect 416 /e/416
Redirect 417 /e/417
Redirect 418 /e/418
Redirect 419 /e/419
Redirect 420 /e/420
Redirect 421 /e/421
Redirect 422 /e/422
Redirect 423 /e/423
Redirect 424 /e/424
Redirect 425 /e/425
Redirect 426 /e/426
Redirect 500 /e/500
Redirect 501 /e/501
Redirect 502 /e/502
Redirect 503 /e/503
Redirect 504 /e/504
Redirect 505 /e/505
Redirect 506 /e/506
Redirect 507 /e/507
Redirect 508 /e/508
Redirect 509 /e/509
Redirect 510 /e/510</pre>
<h3> <a href="#php-header-grabber-script" rel="nofollow"  name="php-header-grabber-script" id="php-header-grabber-script">PHP script that gets and outputs the Headers/Content</a> </h3>
<p>Now all I have to do is add 57 Redirect Directives to my htaccess, and then request each of them 1 at a time from my browser to see the result, and use a packet sniffing program like  <a href="http://wireshark.askapache.com" rel="nofollow" >WireShark</a>  to see the Headers.  Uh, scratch that, that would take way too long!</p>
<p>Instead I hacked up a simple php script using  <a href="http://www.askapache.com/phpbb/sending-post-form-data-with-php-curl.html">cURL</a>  to automate sending GET Requests to each of the 57 Redirect URL-paths. A side benefit of using the php script is that it performs all 57 Requests concurrently and saves each Requests returned headers and content to an output buffer.  After all 57 have been queried, the output buffer is flushed to the browser.</p>
<pre>&lt;?php
$SITENAME=&#039;http://www.askapache.com&#039;;
&nbsp;
$CODES = array(array(&#039;100&#039;,&#039;101&#039;,&#039;102&#039;),
array(&#039;200&#039;,&#039;201&#039;,&#039;202&#039;,&#039;203&#039;,&#039;204&#039;,&#039;205&#039;,&#039;206&#039;,&#039;207&#039;),
array(&#039;300&#039;,&#039;301&#039;,&#039;302&#039;,&#039;303&#039;,&#039;304&#039;,&#039;305&#039;,&#039;306&#039;,&#039;307&#039;),
array(&#039;400&#039;,&#039;401&#039;,&#039;402&#039;,&#039;403&#039;,&#039;404&#039;,&#039;405&#039;,&#039;406&#039;,&#039;407&#039;,&#039;408&#039;,&#039;409&#039;,&#039;410&#039;,&#039;411&#039;,&#039;412&#039;,&#039;413&#039;,
&#039;414&#039;,&#039;415&#039;,&#039;416&#039;,&#039;417&#039;,&#039;418&#039;,&#039;419&#039;,&#039;420&#039;,&#039;421&#039;,&#039;422&#039;,&#039;423&#039;,&#039;424&#039;,&#039;425&#039;,&#039;426&#039;),
array(&#039;500&#039;,&#039;501&#039;,&#039;502&#039;,&#039;503&#039;,&#039;504&#039;,&#039;505&#039;,&#039;506&#039;,&#039;507&#039;,&#039;508&#039;,&#039;509&#039;,&#039;510&#039;));
&nbsp;
$TMPSAVETO=&#039;/tmp/&#039;.time().&#039;.txt&#039;;
&nbsp;
# if file exists then delete it
if(is_file($TMPSAVETO))unlink($TMPSAVETO);
&nbsp;
foreach($CODES as $keyd =&gt; $res)
{
foreach($res as $key)
{
$ch = curl_init(&quot;$SITENAME/e/$key&quot;);
$fp = fopen ($TMPSAVETO, &quot;a&quot;);
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt ($ch, CURLOPT_HEADER ,1);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
}
}
$OUT=&#039;&#039;;
ob_start();
header (&quot;Content-Type: text/plain;&quot;);
readfile($TMPSAVETO);
$OUT=ob_get_clean();
echo $OUT;
unlink($TMPSAVETO);
exit;
?&gt;</pre>
<h2> <a href="#headers-returned-content" rel="nofollow"  id="headers-returned-content">Headers and Content Returned</a> </h2>
<h3> <a href="#status-100" rel="nofollow"  name="status-100" id="status-100">100 Continue</a> </h3>
<pre>HTTP/1.1 100 Continue
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;100 Continue&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Continue&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-101" rel="nofollow"  name="status-101" id="status-101">101 Switching Protocols</a> </h3>
<pre>HTTP/1.1 101 Switching Protocols&lt;html&gt;
&lt;head&gt;
&lt;title&gt;101 Switching Protocols&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Switching Protocols&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-102" rel="nofollow"  name="status-102" id="status-102">102 Processing</a> </h3>
<pre>HTTP/1.1 102 Processing
X-Pad: avoid browser bug&lt;html&gt;
&lt;head&gt;
&lt;title&gt;102 Processing&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Processing&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-200" rel="nofollow"  name="status-200" id="status-200">200 OK</a> </h3>
<pre>HTTP/1.1 200 OK
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;200 OK&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;OK&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-201" rel="nofollow"  name="status-201" id="status-201">201 Created</a> </h3>
<pre>HTTP/1.1 201 Created
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;201 Created&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Created&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-202" rel="nofollow"  name="status-202" id="status-202">202 Accepted</a> </h3>
<pre>HTTP/1.1 202 Accepted
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;202 Accepted&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Accepted&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-203" rel="nofollow"  name="status-203" id="status-203">203 Non-Authoritative Information</a> </h3>
<pre>HTTP/1.1 203 Non-Authoritative Information
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;203 Non-Authoritative Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Non-Authoritative Information&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-204" rel="nofollow"  name="status-204" id="status-204">204 No Content</a> </h3>
<pre>HTTP/1.1 204 No Content
Content-Type: text/plain; charset=UTF-8
&nbsp;</pre>
<h3> <a href="#status-205" rel="nofollow"  name="status-205" id="status-205">205 Reset Content</a> </h3>
<pre>HTTP/1.1 205 Reset Content&lt;html&gt;
&lt;head&gt;
&lt;title&gt;205 Reset Content&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Reset Content&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-206" rel="nofollow"  name="status-206" id="status-206">206 Partial Content</a> </h3>
<pre>HTTP/1.1 206 Partial Content&lt;html&gt;
&lt;head&gt;
&lt;title&gt;206 Partial Content&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Partial Content&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-207" rel="nofollow"  name="status-207" id="status-207">207 Multi-Status</a> </h3>
<pre>HTTP/1.1 207 Multi-Status
X-Pad: avoid browser bug&lt;html&gt;
&lt;head&gt;
&lt;title&gt;207 Multi-Status&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Multi-Status&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-300" rel="nofollow"  name="status-300" id="status-300">300 Multiple Choices</a> </h3>
<pre>HTTP/1.1 300 Multiple Choices
Location: http://www.askapache.com/?s=300&lt;html&gt;
&lt;head&gt;
&lt;title&gt;300 Multiple Choices&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Multiple Choices&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-301" rel="nofollow"  name="status-301" id="status-301">301 Moved Permanently</a> </h3>
<pre>HTTP/1.1 301 Moved Permanently
Location: http://www.askapache.com/?s=301&lt;html&gt;
&lt;head&gt;
&lt;title&gt;301 Moved Permanently&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Moved Permanently&lt;/h1&gt;
&lt;p&gt;The document has moved  &lt;a href=&quot;http://www.askapache.com/?s=301&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-302" rel="nofollow"  name="status-302" id="status-302">302 Found</a> </h3>
<pre>HTTP/1.1 302 Found
Location: http://www.askapache.com/?s=302&lt;html&gt;
&lt;head&gt;
&lt;title&gt;302 Found&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Found&lt;/h1&gt;
&lt;p&gt;The document has moved  &lt;a href=&quot;http://www.askapache.com/?s=302&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-303" rel="nofollow"  name="status-303" id="status-303">303 See Other</a> </h3>
<pre>HTTP/1.1 303 See Other
Location: http://www.askapache.com/?s=303&lt;html&gt;
&lt;head&gt;
&lt;title&gt;303 See Other&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;See Other&lt;/h1&gt;
&lt;p&gt;The answer to your request is located  &lt;a href=&quot;http://www.askapache.com/?s=303&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-304" rel="nofollow"  name="status-304" id="status-304">304 Not Modified</a> </h3>
<pre>HTTP/1.1 304 Not Modified</pre>
<h3> <a href="#status-305" rel="nofollow"  name="status-305" id="status-305">305 Use Proxy</a> </h3>
<pre>HTTP/1.1 305 Use Proxy
Location: http://www.askapache.com/?s=305&lt;html&gt;
&lt;head&gt;
&lt;title&gt;305 Use Proxy&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Use Proxy&lt;/h1&gt;
&lt;p&gt;This resource is only accessible through the proxy
    http://www.askapache.com/?s=305&lt;br /&gt;You will need to configure your client to use that proxy.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-306" rel="nofollow"  name="status-306" id="status-306">306 unused</a> </h3>
<pre>HTTP/1.1 306 unused
Location: http://www.askapache.com/?s=306&lt;html&gt;
&lt;head&gt;
&lt;title&gt;306 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-307" rel="nofollow"  name="status-307" id="status-307">307 Temporary Redirect</a> </h3>
<pre>HTTP/1.1 307 Temporary Redirect
Location: http://www.askapache.com/?s=307&lt;html&gt;
&lt;head&gt;
&lt;title&gt;307 Temporary Redirect&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Temporary Redirect&lt;/h1&gt;
&lt;p&gt;The document has moved  &lt;a href=&quot;http://www.askapache.com/?s=307&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-400" rel="nofollow"  name="status-400" id="status-400">400 Bad Request</a> </h3>
<pre>HTTP/1.1 400 Bad Request
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;400 Bad Request&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Bad Request&lt;/h1&gt;
&lt;p&gt;Your browser sent a request that this server could not understand.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-401" rel="nofollow"  name="status-401" id="status-401">401 Authorization Required</a> </h3>
<pre>HTTP/1.1 401 Authorization Required&lt;html&gt;
&lt;head&gt;
&lt;title&gt;401 Authorization Required&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Authorization Required&lt;/h1&gt;
&lt;p&gt;This server could not verify that you
    are authorized to access the document
    requested.  Either you supplied the wrong
    credentials (e.g., bad password), or your
    browser doesn&#039;t understand how to supply
    the credentials required.&lt;/p&gt;
&lt;p&gt;Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-402" rel="nofollow"  name="status-402" id="status-402">402 Payment Required</a> </h3>
<pre>HTTP/1.1 402 Payment Required&lt;html&gt;
&lt;head&gt;
&lt;title&gt;402 Payment Required&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Payment Required&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-403" rel="nofollow"  name="status-403" id="status-403">403 Forbidden</a> </h3>
<pre>HTTP/1.1 403 Forbidden&lt;html&gt;
&lt;head&gt;
&lt;title&gt;403 Forbidden&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Forbidden&lt;/h1&gt;
&lt;p&gt;You don&#039;t have permission to access /e/403
    on this server.&lt;/p&gt;
&lt;p&gt;Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-404" rel="nofollow"  name="status-404" id="status-404">404 Not Found</a> </h3>
<pre>HTTP/1.1 404 Not Found&lt;html&gt;
&lt;head&gt;
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Not Found&lt;/h1&gt;
&lt;p&gt;The requested URL /e/404 was not found on this server.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p class="anote"><span>NOTE:</span><br />You will most definately want to check out and use the <a href="http://www.askapache.com/seo/404-google-wordpress-plugin.html" title="404 Error Page WordPress Plugin">Google 404 Error Page</a> if you run WordPress.</p>
<h3> <a href="#status-405" rel="nofollow"  name="status-405" id="status-405">405 Method Not Allowed</a> </h3>
<pre>HTTP/1.1 405 Method Not Allowed
Allow: TRACE
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;405 Method Not Allowed&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Method Not Allowed&lt;/h1&gt;
&lt;p&gt;The requested method GET is not allowed for the URL /e/405.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-406" rel="nofollow"  name="status-406" id="status-406">406 Not Acceptable</a> </h3>
<pre>HTTP/1.1 406 Not Acceptable
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;406 Not Acceptable&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Not Acceptable&lt;/h1&gt;
&lt;p&gt;An appropriate representation of the requested resource /e/406 could not be found on this server.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-407" rel="nofollow"  name="status-407" id="status-407">407 Proxy Authentication Required</a> </h3>
<pre>HTTP/1.1 407 Proxy Authentication Required&lt;html&gt;
&lt;head&gt;
&lt;title&gt;407 Proxy Authentication Required&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Proxy Authentication Required&lt;/h1&gt;
&lt;p&gt;This server could not verify that you
    are authorized to access the document
    requested.  Either you supplied the wrong
    credentials (e.g., bad password), or your
    browser doesn&#039;t understand how to supply
    the credentials required.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-408" rel="nofollow"  name="status-408" id="status-408">408 Request Time-out</a> </h3>
<pre>HTTP/1.1 408 Request Time-out
Connection: close
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;408 Request Time-out&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Request Time-out&lt;/h1&gt;
&lt;p&gt;Server timeout waiting for the HTTP request from the client.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-409" rel="nofollow"  name="status-409" id="status-409">409 Conflict</a> </h3>
<pre>HTTP/1.1 409 Conflict
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;409 Conflict&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Conflict&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-410" rel="nofollow"  name="status-410" id="status-410">410 Gone</a> </h3>
<pre>HTTP/1.1 410 Gone
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;410 Gone&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Gone&lt;/h1&gt;
&lt;p&gt;The requested resource&lt;br /&gt;/e/410&lt;br /&gt;is no longer available on this server and there is no forwarding address.
    Please remove all references to this resource.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-411" rel="nofollow"  name="status-411" id="status-411">411 Length Required</a> </h3>
<pre>HTTP/1.1 411 Length Required
Connection: close
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;411 Length Required&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Length Required&lt;/h1&gt;
&lt;p&gt;A request of the requested method GET requires a valid Content-length.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-412" rel="nofollow"  name="status-412" id="status-412">412 Precondition Failed</a> </h3>
<pre>HTTP/1.1 412 Precondition Failed
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;412 Precondition Failed&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Precondition Failed&lt;/h1&gt;
&lt;p&gt;The precondition on the request for the URL /e/412 evaluated to false.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-413" rel="nofollow"  name="status-413" id="status-413">413 Request Entity Too Large</a> </h3>
<pre>HTTP/1.1 413 Request Entity Too Large
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;413 Request Entity Too Large&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Request Entity Too Large&lt;/h1&gt;
The requested resource&lt;br /&gt;/e/413&lt;br /&gt;does not allow request data with GET requests, or the amount of data provided in
the request exceeds the capacity limit.
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-414" rel="nofollow"  name="status-414" id="status-414">414 Request-URI Too Large</a> </h3>
<pre>HTTP/1.1 414 Request-URI Too Large
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;414 Request-URI Too Large&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Request-URI Too Large&lt;/h1&gt;
&lt;p&gt;The requested URL&#039;s length exceeds the capacity
    limit for this server.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-415" rel="nofollow"  name="status-415" id="status-415">415 Unsupported Media Type</a> </h3>
<pre>HTTP/1.1 415 Unsupported Media Type&lt;html&gt;
&lt;head&gt;
&lt;title&gt;415 Unsupported Media Type&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Unsupported Media Type&lt;/h1&gt;
&lt;p&gt;The supplied request data is not in a format
    acceptable for processing by this resource.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-416" rel="nofollow"  name="status-416" id="status-416">416 Requested Range Not Satisfiable</a> </h3>
<pre>HTTP/1.1 416 Requested Range Not Satisfiable</pre>
<h3> <a href="#status-417" rel="nofollow"  name="status-417" id="status-417">417 Expectation Failed</a> </h3>
<pre>HTTP/1.1 417 Expectation Failed&lt;html&gt;
&lt;head&gt;
&lt;title&gt;417 Expectation Failed&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Expectation Failed&lt;/h1&gt;
&lt;p&gt;The expectation given in the Expect request-header
    field could not be met by this server.&lt;/p&gt;
&lt;p&gt;The client sent&lt;pre&gt;
    Expect: &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-418" rel="nofollow"  name="status-418" id="status-418">418 I&#8217;m a teapot</a> </h3>
<pre>HTTP/1.1 418 I&#039;m a teapot&lt;html&gt;
&lt;head&gt;
&lt;title&gt;418 I&#039;m a teapot&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;I&#039;m a teapot&lt;/h1&gt;
&lt;p&gt;Unfortunately this coffee machine is out of coffee.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-419" rel="nofollow"  name="status-419" id="status-419">419 unused</a> </h3>
<pre>HTTP/1.1 419 unused&lt;html&gt;
&lt;head&gt;
&lt;title&gt;419 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-420" rel="nofollow"  name="status-420" id="status-420">420 unused</a> </h3>
<pre>HTTP/1.1 420 unused&lt;html&gt;
&lt;head&gt;
&lt;title&gt;420 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-421" rel="nofollow"  name="status-421" id="status-421">421 unused</a> </h3>
<pre>HTTP/1.1 421 unused&lt;html&gt;
&lt;head&gt;
&lt;title&gt;421 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-422" rel="nofollow"  name="status-422" id="status-422">422 Unprocessable Entity</a> </h3>
<pre>HTTP/1.1 422 Unprocessable Entity&lt;html&gt;
&lt;head&gt;
&lt;title&gt;422 Unprocessable Entity&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Unprocessable Entity&lt;/h1&gt;
&lt;p&gt;The server understands the media type of the
    request entity, but was unable to process the
    contained instructions.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-423" rel="nofollow"  name="status-423" id="status-423">423 Locked</a> </h3>
<pre>HTTP/1.1 423 Locked&lt;html&gt;
&lt;head&gt;
&lt;title&gt;423 Locked&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Locked&lt;/h1&gt;
&lt;p&gt;The requested resource is currently locked.
    The lock must be released or proper identification
    given before the method can be applied.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-424" rel="nofollow"  name="status-424" id="status-424">424 Failed Dependency</a> </h3>
<pre>HTTP/1.1 424 Failed Dependency&lt;html&gt;
&lt;head&gt;
&lt;title&gt;424 Failed Dependency&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Failed Dependency&lt;/h1&gt;
&lt;p&gt;The method could not be performed on the resource
    because the requested action depended on another
    action and that other action failed.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-425" rel="nofollow"  name="status-425" id="status-425">425 No code</a> </h3>
<pre>HTTP/1.1 425 No code&lt;html&gt;
&lt;head&gt;
&lt;title&gt;425 No code&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;No code&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-426" rel="nofollow"  name="status-426" id="status-426">426 Upgrade Required</a> </h3>
<pre>HTTP/1.1 426 Upgrade Required&lt;html&gt;
&lt;head&gt;
&lt;title&gt;426 Upgrade Required&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Upgrade Required&lt;/h1&gt;
&lt;p&gt;The requested resource can only be retrieved
    using SSL.  The server is willing to upgrade the current
    connection to SSL, but your client doesn&#039;t support it.
    Either upgrade your client, or try requesting the page
    using https:// &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-500" rel="nofollow"  name="status-500" id="status-500">500 Internal Server Error</a> </h3>
<pre>HTTP/1.1 500 Internal Server Error
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;500 Internal Server Error&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Internal Server Error&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;p&gt;Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-501" rel="nofollow"  name="status-501" id="status-501">501 Method Not Implemented</a> </h3>
<pre>HTTP/1.1 501 Method Not Implemented
Allow: TRACE
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;501 Method Not Implemented&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Method Not Implemented&lt;/h1&gt;
&lt;p&gt;GET to /e/501 not supported.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-502" rel="nofollow"  name="status-502" id="status-502">502 Bad Gateway</a> </h3>
<pre>HTTP/1.1 502 Bad Gateway
X-Pad: avoid browser bug&lt;html&gt;
&lt;head&gt;
&lt;title&gt;502 Bad Gateway&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Bad Gateway&lt;/h1&gt;
&lt;p&gt;The proxy server received an invalid
    response from an upstream server.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-503" rel="nofollow"  name="status-503" id="status-503">503 Service Temporarily Unavailable</a> </h3>
<pre>HTTP/1.1 503 Service Temporarily Unavailable
Connection: close&lt;html&gt;
&lt;head&gt;
&lt;title&gt;503 Service Temporarily Unavailable&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Service Temporarily Unavailable&lt;/h1&gt;
&lt;p&gt;The server is temporarily unable to service your
    request due to maintenance downtime or capacity
    problems. Please try again later.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-504" rel="nofollow"  name="status-504" id="status-504">504 Gateway Time-out</a> </h3>
<pre>HTTP/1.1 504 Gateway Time-out&lt;html&gt;
&lt;head&gt;
&lt;title&gt;504 Gateway Time-out&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Gateway Time-out&lt;/h1&gt;
&lt;p&gt;The proxy server did not receive a timely response
    from the upstream server.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-505" rel="nofollow"  name="status-505" id="status-505">505 HTTP Version Not Supported</a> </h3>
<pre>HTTP/1.1 505 HTTP Version Not Supported&lt;html&gt;
&lt;head&gt;
&lt;title&gt;505 HTTP Version Not Supported&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;HTTP Version Not Supported&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-506" rel="nofollow"  name="status-506" id="status-506">506 Variant Also Negotiates</a> </h3>
<pre>HTTP/1.1 506 Variant Also Negotiates&lt;html&gt;
&lt;head&gt;
&lt;title&gt;506 Variant Also Negotiates&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Variant Also Negotiates&lt;/h1&gt;
&lt;p&gt;A variant for the requested resource
    &lt;pre&gt;
    /e/506
    &lt;/pre&gt;
    is itself a negotiable resource. This indicates a configuration error.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-507" rel="nofollow"  name="status-507" id="status-507">507 Insufficient Storage</a> </h3>
<pre>HTTP/1.1 507 Insufficient Storage&lt;html&gt;
&lt;head&gt;
&lt;title&gt;507 Insufficient Storage&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Insufficient Storage&lt;/h1&gt;
&lt;p&gt;The method could not be performed on the resource
    because the server is unable to store the
    representation needed to successfully complete the
    request.  There is insufficient free space left in
    your storage allocation.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-508" rel="nofollow"  name="status-508" id="status-508">508 unused</a> </h3>
<pre>HTTP/1.1 508 unused&lt;html&gt;
&lt;head&gt;
&lt;title&gt;508 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-509" rel="nofollow"  name="status-509" id="status-509">509 unused</a> </h3>
<pre>HTTP/1.1 509 unused
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;509 unused&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;unused&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or misconfigurationand was unable to complete your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator, a@s.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available in the server error log.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3> <a href="#status-510" rel="nofollow"  name="status-510" id="status-510">510 Not Extended</a> </h3>
<pre>HTTP/1.1 510 Not Extended
X-Pad: avoid browser bug
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;510 Not Extended&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Not Extended&lt;/h1&gt;
&lt;p&gt;A mandatory extension policy in the request is not
    accepted by the server for this resource.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h2> <a href="#apache-source-code" rel="nofollow"  name="apache-source-code" id="apache-source-code">Apache Source Code</a> </h2>
<h3> <a href="#httpdh-h" rel="nofollow"  name="httpdh-h" id="httpdh-h">httpd.h</a> </h3>
<p>From <a href="http://uploads.askapache.com/2007/02/httpd.h" rel="nofollow"  title="httpd.h Apache">httpd.h</a> </p>
<pre>/**
* The size of the static array in http_protocol.c for storing
* all of the potential response status-lines (a sparse table).
* A future version should dynamically generate the apr_table_t at startup.
*/
#define RESPONSE_CODES 57
#define HTTP_CONTINUE            100
#define HTTP_SWITCHING_PROTOCOLS       101
#define HTTP_PROCESSING          102
#define HTTP_OK              200
#define HTTP_CREATED             201
#define HTTP_ACCEPTED            202
#define HTTP_NON_AUTHORITATIVE       203
#define HTTP_NO_CONTENT          204
#define HTTP_RESET_CONTENT         205
#define HTTP_PARTIAL_CONTENT         206
#define HTTP_MULTI_STATUS          207
#define HTTP_MULTIPLE_CHOICES        300
#define HTTP_MOVED_PERMANENTLY       301
&nbsp;
#define HTTP_MOVED_TEMPORARILY       302
#define HTTP_SEE_OTHER           303
#define HTTP_NOT_MODIFIED          304
#define HTTP_USE_PROXY           305
#define HTTP_TEMPORARY_REDIRECT      307
#define HTTP_BAD_REQUEST           400
#define HTTP_UNAUTHORIZED          401
#define HTTP_PAYMENT_REQUIRED        402
#define HTTP_FORBIDDEN           403
#define HTTP_NOT_FOUND           404
#define HTTP_METHOD_NOT_ALLOWED      405
#define HTTP_NOT_ACCEPTABLE        406
#define HTTP_PROXY_AUTHENTICATION_REQUIRED 407
#define HTTP_REQUEST_TIME_OUT        408
#define HTTP_CONFLICT            409
#define HTTP_GONE              410
#define HTTP_LENGTH_REQUIRED         411
#define HTTP_PRECONDITION_FAILED       412
#define HTTP_REQUEST_ENTITY_TOO_LARGE    413
#define HTTP_REQUEST_URI_TOO_LARGE     414
#define HTTP_UNSUPPORTED_MEDIA_TYPE    415
#define HTTP_RANGE_NOT_SATISFIABLE     416
#define HTTP_EXPECTATION_FAILED      417
#define HTTP_UNPROCESSABLE_ENTITY      422
#define HTTP_LOCKED            423
#define HTTP_FAILED_DEPENDENCY       424
#define HTTP_UPGRADE_REQUIRED        426
#define HTTP_INTERNAL_SERVER_ERROR     500
#define HTTP_NOT_IMPLEMENTED         501
#define HTTP_BAD_GATEWAY           502
#define HTTP_SERVICE_UNAVAILABLE       503
#define HTTP_GATEWAY_TIME_OUT        504
#define HTTP_VERSION_NOT_SUPPORTED     505
#define HTTP_VARIANT_ALSO_VARIES       506
#define HTTP_INSUFFICIENT_STORAGE      507
#define HTTP_NOT_EXTENDED          510
&nbsp;
/** is the status code informational */
#define ap_is_HTTP_INFO(x)     (((x) &gt;= 100)&amp;&amp;((x) &lt; 200))
/** is the status code OK ?*/
#define ap_is_HTTP_SUCCESS(x)    (((x) &gt;= 200)&amp;&amp;((x) &lt; 300))
/** is the status code a redirect */
#define ap_is_HTTP_REDIRECT(x)   (((x) &gt;= 300)&amp;&amp;((x) &lt; 400))
/** is the status code a error (client or server) */
#define ap_is_HTTP_ERROR(x)    (((x) &gt;= 400)&amp;&amp;((x) &lt; 600))
/** is the status code a client error  */
#define ap_is_HTTP_CLIENT_ERROR(x) (((x) &gt;= 400)&amp;&amp;((x) &lt; 500))
/** is the status code a server error  */
#define ap_is_HTTP_SERVER_ERROR(x) (((x) &gt;= 500)&amp;&amp;((x) &lt; 600))
/** is the status code a (potentially) valid response code?  */
#define ap_is_HTTP_VALID_RESPONSE(x) (((x) &gt;= 100)&amp;&amp;((x) &lt; 600))
&nbsp;
/** should the status code drop the connection */
#define ap_status_drops_connection(x) \
(((x) == HTTP_BAD_REQUEST)       || \
((x) == HTTP_REQUEST_TIME_OUT)    || \
((x) == HTTP_LENGTH_REQUIRED)     || \
((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
((x) == HTTP_INTERNAL_SERVER_ERROR) || \
((x) == HTTP_SERVICE_UNAVAILABLE) || \
((x) == HTTP_NOT_IMPLEMENTED))</pre>
<h4>HTTP_INFO</h4>
<p><strong>Is the status code (x) informational?</strong></p>
<pre>x &gt;= 100 &amp;&amp; x &lt; 200</pre>
<h4>HTTP_SUCCESS</h4>
<p><strong>Is the status code (x) OK?</strong></p>
<pre>x &gt;= 200 &amp;&amp; x &lt; 300</pre>
<h4>HTTP_REDIRECT</h4>
<p><strong>Is the status code (x) a redirect?</strong></p>
<pre>x &gt;= 300 &amp;&amp; x &lt; 400</pre>
<h4>HTTP_ERROR</h4>
<p><strong>Is the status code (x) a error (client or server)?</strong></p>
<pre>x &gt;= 400 &amp;&amp; x &lt; 600</pre>
<h4>HTTP_CLIENT_ERROR</h4>
<p><strong>Is the status code (x) a client error?</strong></p>
<pre>x &gt;= 400 &amp;&amp; x &lt; 500</pre>
<h4>HTTP_SERVER_ERROR</h4>
<p><strong>Is the status code (x) a server error?</strong></p>
<pre>x &gt;= 500 &amp;&amp; x &lt; 600</pre>
<h4>HTTP_VALID_RESPONSE</h4>
<p><strong>Is the status code (x) a (potentially) valid response code?</strong></p>
<pre>x &gt;= 100 &amp;&amp; x &lt; 600</pre>
<h3> <a href="#http_protocol-c" rel="nofollow"  name="http_protocol-c" id="http_protocol-c">http_protocol.c</a> </h3>
<p>From <a href="http://uploads.askapache.com/2007/02/http_protocol.c" rel="nofollow"  title="http_protocol.c">http_protocol.c</a> </p>
<pre>static const char * status_lines[RESPONSE_CODES] =
static const char * const status_lines[RESPONSE_CODES] =
&quot;100 Continue&quot;,
&quot;101 Switching Protocols&quot;,
&quot;102 Processing&quot;,
&quot;200 OK&quot;,
&quot;201 Created&quot;,
&quot;202 Accepted&quot;,
&quot;203 Non-Authoritative Information&quot;,
&quot;204 No Content&quot;,
&quot;205 Reset Content&quot;,
&quot;206 Partial Content&quot;,
&quot;207 Multi-Status&quot;,
&quot;300 Multiple Choices&quot;,
&quot;301 Moved Permanently&quot;,
&quot;302 Found&quot;,
&quot;303 See Other&quot;,
&quot;304 Not Modified&quot;,
&quot;305 Use Proxy&quot;,
&quot;306 unused&quot;,
&quot;307 Temporary Redirect&quot;,
&quot;400 Bad Request&quot;,
&quot;401 Authorization Required&quot;,
&quot;402 Payment Required&quot;,
&quot;403 Forbidden&quot;,
&quot;404 Not Found&quot;,
&quot;405 Method Not Allowed&quot;,
&quot;406 Not Acceptable&quot;,
&quot;407 Proxy Authentication Required&quot;,
&quot;408 Request Time-out&quot;,
&quot;409 Conflict&quot;,
&quot;410 Gone&quot;,
&quot;411 Length Required&quot;,
&quot;412 Precondition Failed&quot;,
&quot;413 Request Entity Too Large&quot;,
&quot;414 Request-URI Too Large&quot;,
&quot;415 Unsupported Media Type&quot;,
&quot;416 Requested Range Not Satisfiable&quot;,
&quot;417 Expectation Failed&quot;,
&quot;418 unused&quot;,
&quot;419 unused&quot;,
&quot;420 unused&quot;,
&quot;421 unused&quot;,
&quot;422 Unprocessable Entity&quot;,
&quot;423 Locked&quot;,
&quot;424 Failed Dependency&quot;,
&quot;425 No code&quot;,
&quot;426 Upgrade Required&quot;,
&quot;500 Internal Server Error&quot;,
&quot;501 Method Not Implemented&quot;,
&quot;502 Bad Gateway&quot;,
&quot;503 Service Temporarily Unavailable&quot;,
&quot;504 Gateway Time-out&quot;,
&quot;505 HTTP Version Not Supported&quot;,
&quot;506 Variant Also Negotiates&quot;,
&quot;507 Insufficient Storage&quot;,
&quot;508 unused&quot;,
&quot;509 unused&quot;,
&quot;510 Not Extended&quot;</pre>
<h2>IANA HTTP Status Code Registry</h2>
<table cellpadding="3" cellspacing="0">
<thead>
<tr>
<th>Value</th>
<th>Description</th>
<th>Reference</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>Continue</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.1.1" rel="nofollow" >Section 10.1.1</a> </td>
</tr>
<tr>
<td>101</td>
<td>Switching Protocols</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.1.2" rel="nofollow" >Section 10.1.2</a> </td>
</tr>
<tr>
<td>102</td>
<td>Processing</td>
<td> <a href="#RFC2518" rel="nofollow" ><cite title="HTTP Extensions for Distributed Authoring -- WEBDAV">[RFC2518]</cite></a> , <a href="http://rfc.askapache.com/rfc2518#section-10.1" rel="nofollow" >Section 10.1</a> </td>
</tr>
<tr>
<td>200</td>
<td>OK</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.1" rel="nofollow" >Section 10.2.1</a> </td>
</tr>
<tr>
<td>201</td>
<td>Created</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.2" rel="nofollow" >Section 10.2.2</a> </td>
</tr>
<tr>
<td>202</td>
<td>Accepted</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.3" rel="nofollow" >Section 10.2.3</a> </td>
</tr>
<tr>
<td>203</td>
<td>Non-Authoritative Information</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.4" rel="nofollow" >Section 10.2.4</a> </td>
</tr>
<tr>
<td>204</td>
<td>No Content</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.5" rel="nofollow" >Section 10.2.5</a> </td>
</tr>
<tr>
<td>205</td>
<td>Reset Content</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.6" rel="nofollow" >Section 10.2.6</a> </td>
</tr>
<tr>
<td>206</td>
<td>Partial Content</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.2.7" rel="nofollow" >Section 10.2.7</a> </td>
</tr>
<tr>
<td>207</td>
<td>Multi-Status</td>
<td> <a href="#RFC4918" rel="nofollow" ><cite title="HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)">[RFC4918]</cite></a> , <a href="http://rfc.askapache.com/rfc4918#section-11.1" rel="nofollow" >Section 11.1</a> </td>
</tr>
<tr>
<td>226</td>
<td>IM Used</td>
<td> <a href="#RFC3229" rel="nofollow" ><cite title="Delta encoding in HTTP">[RFC3229]</cite></a> , <a href="http://rfc.askapache.com/rfc3229#section-10.4.1" rel="nofollow" >Section 10.4.1</a> </td>
</tr>
<tr>
<td>300</td>
<td>Multiple Choices</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.1" rel="nofollow" >Section 10.3.1</a> </td>
</tr>
<tr>
<td>301</td>
<td>Moved Permanently</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.2" rel="nofollow" >Section 10.3.2</a> </td>
</tr>
<tr>
<td>302</td>
<td>Found</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.3" rel="nofollow" >Section 10.3.3</a> </td>
</tr>
<tr>
<td>303</td>
<td>See Other</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.4" rel="nofollow" >Section 10.3.4</a> </td>
</tr>
<tr>
<td>304</td>
<td>Not Modified</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.5" rel="nofollow" >Section 10.3.5</a> </td>
</tr>
<tr>
<td>305</td>
<td>Use Proxy</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.6" rel="nofollow" >Section 10.3.6</a> </td>
</tr>
<tr>
<td>306</td>
<td>(Reserved)</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.7" rel="nofollow" >Section 10.3.7</a> </td>
</tr>
<tr>
<td>307</td>
<td>Temporary Redirect</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.3.8" rel="nofollow" >Section 10.3.8</a> </td>
</tr>
<tr>
<td>400</td>
<td>Bad Request</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.1" rel="nofollow" >Section 10.4.1</a> </td>
</tr>
<tr>
<td>401</td>
<td>Unauthorized</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.2" rel="nofollow" >Section 10.4.2</a> </td>
</tr>
<tr>
<td>402</td>
<td>Payment Required</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.3" rel="nofollow" >Section 10.4.3</a> </td>
</tr>
<tr>
<td>403</td>
<td>Forbidden</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.4" rel="nofollow" >Section 10.4.4</a> </td>
</tr>
<tr>
<td>404</td>
<td>Not Found</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.5" rel="nofollow" >Section 10.4.5</a> </td>
</tr>
<tr>
<td>405</td>
<td>Method Not Allowed</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.6" rel="nofollow" >Section 10.4.6</a> </td>
</tr>
<tr>
<td>406</td>
<td>Not Acceptable</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.7" rel="nofollow" >Section 10.4.7</a> </td>
</tr>
<tr>
<td>407</td>
<td>Proxy Authentication Required</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.8" rel="nofollow" >Section 10.4.8</a> </td>
</tr>
<tr>
<td>408</td>
<td>Request Timeout</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.9" rel="nofollow" >Section 10.4.9</a> </td>
</tr>
<tr>
<td>409</td>
<td>Conflict</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.10" rel="nofollow" >Section 10.4.10</a> </td>
</tr>
<tr>
<td>410</td>
<td>Gone</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.11" rel="nofollow" >Section 10.4.11</a> </td>
</tr>
<tr>
<td>411</td>
<td>Length Required</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.12" rel="nofollow" >Section 10.4.12</a> </td>
</tr>
<tr>
<td>412</td>
<td>Precondition Failed</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.13" rel="nofollow" >Section 10.4.13</a> </td>
</tr>
<tr>
<td>413</td>
<td>Request Entity Too Large</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.14" rel="nofollow" >Section 10.4.14</a> </td>
</tr>
<tr>
<td>414</td>
<td>Request-URI Too Long</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.15" rel="nofollow" >Section 10.4.15</a> </td>
</tr>
<tr>
<td>415</td>
<td>Unsupported Media Type</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.16" rel="nofollow" >Section 10.4.16</a> </td>
</tr>
<tr>
<td>416</td>
<td>Requested Range Not Satisfiable</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.17" rel="nofollow" >Section 10.4.17</a> </td>
</tr>
<tr>
<td>417</td>
<td>Expectation Failed</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.4.18" rel="nofollow" >Section 10.4.18</a> </td>
</tr>
<tr>
<td>422</td>
<td>Unprocessable Entity</td>
<td> <a href="#RFC4918" rel="nofollow" ><cite title="HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)">[RFC4918]</cite></a> , <a href="http://rfc.askapache.com/rfc4918#section-11.2" rel="nofollow" >Section 11.2</a> </td>
</tr>
<tr>
<td>423</td>
<td>Locked</td>
<td> <a href="#RFC4918" rel="nofollow" ><cite title="HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)">[RFC4918]</cite></a> , <a href="http://rfc.askapache.com/rfc4918#section-11.3" rel="nofollow" >Section 11.3</a> </td>
</tr>
<tr>
<td>424</td>
<td>Failed Dependency</td>
<td> <a href="#RFC4918" rel="nofollow" ><cite title="HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)">[RFC4918]</cite></a> , <a href="http://rfc.askapache.com/rfc4918#section-11.4" rel="nofollow" >Section 11.4</a> </td>
</tr>
<tr>
<td>426</td>
<td>Upgrade Required</td>
<td> <a href="#RFC2817" rel="nofollow" ><cite title="Upgrading to TLS Within HTTP/1.1">[RFC2817]</cite></a> , <a href="http://rfc.askapache.com/rfc2817#section-6" rel="nofollow" >Section 6</a> </td>
</tr>
<tr>
<td>500</td>
<td>Internal Server Error</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.1" rel="nofollow" >Section 10.5.1</a> </td>
</tr>
<tr>
<td>501</td>
<td>Not Implemented</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.2" rel="nofollow" >Section 10.5.2</a> </td>
</tr>
<tr>
<td>502</td>
<td>Bad Gateway</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.3" rel="nofollow" >Section 10.5.3</a> </td>
</tr>
<tr>
<td>503</td>
<td>Service Unavailable</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.4" rel="nofollow" >Section 10.5.4</a> </td>
</tr>
<tr>
<td>504</td>
<td>Gateway Timeout</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.5" rel="nofollow" >Section 10.5.5</a> </td>
</tr>
<tr>
<td>505</td>
<td>HTTP Version Not Supported</td>
<td> <a href="#RFC2616" rel="nofollow" ><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a> , <a href="http://rfc.askapache.com/rfc2616#section-10.5.6" rel="nofollow" >Section 10.5.6</a> </td>
</tr>
<tr>
<td>506</td>
<td>Variant Also Negotiates</td>
<td> <a href="#RFC2295" rel="nofollow" ><cite title="Transparent Content Negotiation in HTTP">[RFC2295]</cite></a> , <a href="http://rfc.askapache.com/rfc2295#section-8.1" rel="nofollow" >Section 8.1</a> </td>
</tr>
<tr>
<td>507</td>
<td>Insufficient Storage</td>
<td> <a href="#RFC4918" rel="nofollow" ><cite title="HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)">[RFC4918]</cite></a> , <a href="http://rfc.askapache.com/rfc4918#section-11.5" rel="nofollow" >Section 11.5</a> </td>
</tr>
<tr>
<td>510</td>
<td>Not Extended</td>
<td> <a href="#RFC2774" rel="nofollow" ><cite title="An HTTP Extension Framework">[RFC2774]</cite></a> , <a href="http://rfc.askapache.com/rfc2774#section-7" rel="nofollow" >Section 7</a> </td>
</tr>
</tbody>
</table>
<h2>WordPress 2.8 Changes</h2>
<p>I just learned that <a href="https://core.trac.wordpress.org/ticket/9297" rel="nofollow" >my modification</a> to the WordPress core was <a href="https://core.trac.wordpress.org/changeset/10740" rel="nofollow" >accepted</a> and will be implemented for version 2.8!  This may mean WordPress is the only 100% HTTP/1.1 compliant software on the net!  Below is the new list (<em>I thought someone out there could use the php array</em>) and as you can see, unfortunately<strong>418 I&#8217;m a teapot</strong>didn&#8217;t make it ;)</p>
<pre>$wp_header_to_desc = array(
  100 =&gt; &#039;Continue&#039;,
  101 =&gt; &#039;Switching Protocols&#039;,
  102 =&gt; &#039;Processing&#039;,
&nbsp;
  200 =&gt; &#039;OK&#039;,
  201 =&gt; &#039;Created&#039;,
  202 =&gt; &#039;Accepted&#039;,
  203 =&gt; &#039;Non-Authoritative Information&#039;,
  204 =&gt; &#039;No Content&#039;,
  205 =&gt; &#039;Reset Content&#039;,
  206 =&gt; &#039;Partial Content&#039;,
  207 =&gt; &#039;Multi-Status&#039;,
  226 =&gt; &#039;IM Used&#039;,
&nbsp;
  300 =&gt; &#039;Multiple Choices&#039;,
  301 =&gt; &#039;Moved Permanently&#039;,
  302 =&gt; &#039;Found&#039;,
  303 =&gt; &#039;See Other&#039;,
  304 =&gt; &#039;Not Modified&#039;,
  305 =&gt; &#039;Use Proxy&#039;,
  306 =&gt; &#039;Reserved&#039;,
  307 =&gt; &#039;Temporary Redirect&#039;,
&nbsp;
  400 =&gt; &#039;Bad Request&#039;,
  401 =&gt; &#039;Unauthorized&#039;,
  402 =&gt; &#039;Payment Required&#039;,
  403 =&gt; &#039;Forbidden&#039;,
  404 =&gt; &#039;Not Found&#039;,
  405 =&gt; &#039;Method Not Allowed&#039;,
  406 =&gt; &#039;Not Acceptable&#039;,
  407 =&gt; &#039;Proxy Authentication Required&#039;,
  408 =&gt; &#039;Request Timeout&#039;,
  409 =&gt; &#039;Conflict&#039;,
  410 =&gt; &#039;Gone&#039;,
  411 =&gt; &#039;Length Required&#039;,
  412 =&gt; &#039;Precondition Failed&#039;,
  413 =&gt; &#039;Request Entity Too Large&#039;,
  414 =&gt; &#039;Request-URI Too Long&#039;,
  415 =&gt; &#039;Unsupported Media Type&#039;,
  416 =&gt; &#039;Requested Range Not Satisfiable&#039;,
  417 =&gt; &#039;Expectation Failed&#039;,
  422 =&gt; &#039;Unprocessable Entity&#039;,
  423 =&gt; &#039;Locked&#039;,
  424 =&gt; &#039;Failed Dependency&#039;,
  426 =&gt; &#039;Upgrade Required&#039;,
&nbsp;
  500 =&gt; &#039;Internal Server Error&#039;,
  501 =&gt; &#039;Not Implemented&#039;,
  502 =&gt; &#039;Bad Gateway&#039;,
  503 =&gt; &#039;Service Unavailable&#039;,
  504 =&gt; &#039;Gateway Timeout&#039;,
  505 =&gt; &#039;HTTP Version Not Supported&#039;,
  506 =&gt; &#039;Variant Also Negotiates&#039;,
  507 =&gt; &#039;Insufficient Storage&#039;,
  510 =&gt; &#039;Not Extended&#039;
);</pre>
<h2>RIPE WHOIS</h2>
<blockquote cite="http://labs.ripe.net/content/ripe-database-api-documentation">
<p><p>All the status codes are standard HTTP codes ( <a href="http://www.iana.org/assignments/http-status-codes" rel="nofollow" >http://www.iana.org/assignments/http-status-codes</a> ).</p>
</p>
<p>Clients should avoid any form of coupling with the the text/plain error message contained in response body since it may change between different releases of the API and is only intended as a starting point for indentifying the real causes of the exception event.</p>
<p>The following table gives a brief description of the mapping between standard Whois V.3 responses and the related REST services status codes. Consider this table as just an example of the error mapping strategy, it may change with future releases.</p>
</p>
</blockquote>
<table>
<tbody>
<tr>
<th>System Exception</th>
<th>Whois Error</th>
<th>HTTP Status Code</th>
</tr>
<tr>
<td>IllegalArgumentException</td>
<td></td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>IllegalStateException</td>
<td></td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>UnsupportedOperationException</td>
<td></td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>ObjectNotFoundException</td>
<td></td>
<td>Not Found (404)</td>
</tr>
<tr>
<td>IllegalStateException</td>
<td></td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>IOException</td>
<td></td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>SystemException</td>
<td></td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>TooManyResultsException</td>
<td></td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>No Entries Found (101)</td>
<td>Not Found (404)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Unknown Source (102)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Unknown Object Type (103)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Unknown Attribute in Query (104)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Attribute Is Not Inverse Searchable (105)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>No Search Key Specified (106)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Access Denied (201)</td>
<td>Forbidden (403)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Access Control Limit Reached (202)</td>
<td>Forbidden (403)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Address Passing Not Allowed (203)</td>
<td>Bad Request (400)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Maximum Referral Lines Exceeded (204)</td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Connection Has Been Closed(301)</td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Referral Timeout (302)</td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>No Referral Host (303)</td>
<td>Internal Server Error (500)</td>
</tr>
<tr>
<td>WhoisServerException</td>
<td>Referral Host Not Responding (304)</td>
<td>Internal Server Error (500)</td>
</tr>
</tbody>
</table>
<blockquote cite="http://labs.ripe.net/content/ripe-database-api-documentation">
<p><p>Clients will have to define error messages generic enough to represent the four main error conditions, that are Bad Request, Forbidden, Not Found and Internal Server Error.</p>
<p>For example a possible mapping for client side error messages may be:</p>
</p>
</blockquote>
<table>
<tbody>
<tr>
<th>HTTP Status Code</th>
<th>Error Message</th>
</tr>
<tr>
<td>Bad Request (400)</td>
<td>The service is unable to understand and process the query.</td>
</tr>
<tr>
<td>Forbidden (403)</td>
<td>Query limit exceeded.</td>
</tr>
<tr>
<td>Not Found (404)</td>
<td>No results were found for Your search &#8220;<tt>Search term</tt>&#8220;</td>
</tr>
<tr>
<td>Internal Server Error (500)</td>
<td>The server encountered an unexpected condition which prevented it from fulfilling the request.</td>
</tr>
</tbody>
</table>
<h2>Helpful HTTP Links</h2>
<ol>
<li> <a href="http://www.iana.org/assignments/http-status-codes" rel="nofollow" >IANA registry</a> </li>
<li> <a href="http://rfc.askapache.com/rfc2324" rel="nofollow" >Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)</a> </li>
<li> <a href="http://livedocs.adobe.com/fms/2/docs/00000338.html" rel="nofollow" >Adobe Flash status code definitions (ie 408)</a> </li>
<li> <a href="http://support.microsoft.com/?id=318380" rel="nofollow" >Microsoft Internet Information Server Status Codes and Sub-Codes</a> </li>
<li> <a href="http://zamez.org/httplint?url=http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">httplint</a> </li>
<li> <a href="http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html" rel="nofollow" >HTTP Headers, brief intro.</a> </li>
<li> <a href="http://www.w3.org/TR/cuap" rel="nofollow" >Common User-Agent Issues</a> </li>
<li>[RFC2295] <a href="mailto:koen@win.tue.nl" rel="nofollow"  title="Technische Universiteit Eindhoven">Holtman, K.</a> and <a href="mailto:mutz@hpl.hp.com" rel="nofollow"  title="Hewlett-Packard Company">A.H. Mutz</a> , &#8221; <a href="http://rfc.askapache.com/rfc2295" rel="nofollow" >Transparent Content Negotiation in HTTP</a> &#8220;, RFC 2295, March 1998.</li>
<li>[RFC2518] <a href="mailto:yarong@microsoft.com" rel="nofollow"  title="Microsoft Corporation">Goland, Y.</a> , <a href="mailto:ejw@ics.uci.edu" rel="nofollow"  title="Dept. Of Information and Computer Science, University of California, Irvine">Whitehead, E.</a> , <a href="mailto:asad@netscape.com" rel="nofollow"  title="Netscape">Faizi, A.</a> , <a href="mailto:srcarter@novell.com" rel="nofollow"  title="Novell">Carter, S.R.</a> , and <a href="mailto:dcjensen@novell.com" rel="nofollow"  title="Novell">D. Jensen</a> , &#8221; <a href="http://rfc.askapache.com/rfc2518" rel="nofollow" >HTTP Extensions for Distributed Authoring &#8212; WEBDAV</a> &#8220;, RFC 2518, February 1999.</li>
<li>[RFC2616] <a href="mailto:fielding@ics.uci.edu" rel="nofollow"  title="University of California, Irvine">Fielding, R.</a> , <a href="mailto:jg@w3.org" rel="nofollow"  title="W3C">Gettys, J.</a> , <a href="mailto:mogul@wrl.dec.com" rel="nofollow"  title="Compaq Computer Corporation">Mogul, J.</a> , <a href="mailto:frystyk@w3.org" rel="nofollow"  title="MIT Laboratory for Computer Science">Frystyk, H.</a> , <a href="mailto:masinter@parc.xerox.com" rel="nofollow"  title="Xerox Corporation">Masinter, L.</a> , <a href="mailto:paulle@microsoft.com" rel="nofollow"  title="Microsoft Corporation">Leach, P.</a> , and <a href="mailto:timbl@w3.org" rel="nofollow"  title="W3C">T. Berners-Lee</a> , &#8221; <a href="http://rfc.askapache.com/rfc2616" rel="nofollow" >Hypertext Transfer Protocol &#8212; HTTP/1.1</a> &#8220;, RFC 2616, June 1999.</li>
<li>[RFC2774] <a href="mailto:frystyk@microsoft.com" rel="nofollow"  title="Microsoft Corporation">Nielsen, H.</a> , <a href="mailto:paulle@microsoft.com" rel="nofollow"  title="Microsoft Corporation">Leach, P.</a> , and <a href="mailto:lawrence@agranat.com" rel="nofollow"  title="Agranat Systems, Inc.">S. Lawrence</a> , &#8221; <a href="http://rfc.askapache.com/rfc2774" rel="nofollow" >An HTTP Extension Framework</a> &#8220;, RFC 2774, February 2000.</li>
<li>[RFC2817] Khare, R. and S. Lawrence, &#8221; <a href="http://rfc.askapache.com/rfc2817" rel="nofollow" >Upgrading to TLS Within HTTP/1.1</a> &#8220;, RFC 2817, May 2000.</li>
<li>[RFC3229] Mogul, J., Krishnamurthy, B., Douglis, F., Feldmann, A., Goland, Y., van Hoff, A., and D. Hellerstein, &#8221; <a href="http://rfc.askapache.com/rfc3229" rel="nofollow" >Delta encoding in HTTP</a> &#8220;, RFC 3229, January 2002.</li>
<li>[RFC4918] <a href="mailto:ldusseault@commerce.net" rel="nofollow"  title="CommerceNet">Dusseault, L., Ed.</a> , &#8221; <a href="http://rfc.askapache.com/rfc4918" rel="nofollow" >HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)</a> &#8220;, RFC 4918, June 2007.</li>
</ol>
<p><a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html"></a><a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">HTTP Status Codes and .htaccess ErrorDocuments</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>An AskApache Plugin Upgrade to Rule them All</title>
		<link>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html</link>
		<comments>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html#comments</comments>
		<pubDate>Wed, 29 Jul 2009 17:59:07 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Modules]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[AskApache Google 404]]></category>
		<category><![CDATA[AskApache Password Protection]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Fsockopen]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[htaccess tricks]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[Mod_Setenvif]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server config]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[Username]]></category>
		<category><![CDATA[Wireshark]]></category>
		<category><![CDATA[WordPress Security]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3062</guid>
		<description><![CDATA[<p><a class="IFL" href="http://uploads.askapache.com/2009/07/apache-server-status.png"><img src="http://uploads.askapache.com/2009/07/apache-server-status-350x164.png" alt="apache-server-status" title="apache-server-status" width="350" height="164" class="alignnone size-medium wp-image-3070" /></a>So my blog as been rather quiet for almost a year now, and very few updates if any have been released for my Password Protection PLugin, my Google 404 Plugin, and definately not for my AskApache CrazyCache plugin, which I will be releasing last...  So for all of you who've helped me out by sending me suggestions and notifying me of errors and sticking with it...  Just wanted to <strong>say sorry about that, and thanks for all the great ideas.. </strong> Well, I've been sticking with it as well believe it our not.  I manage to get free days once in a while, and then its <strong>time to jam</strong>.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://uploads.askapache.com/2009/07/apache-server-status.png" rel="nofollow" class="IFL" ><img src="http://uploads.askapache.com/2009/07/apache-server-status-350x164.png" alt="An AskApache Plugin Upgrade to Rule them All" title="apache-server-status" width="350" height="164" class="alignnone size-medium wp-image-3070" /></a>So my blog as been rather quiet for almost a year now, and very few updates if any have been released for my Password Protection PLugin, my Google 404 Plugin, and definately not for my AskApache CrazyCache plugin, which I will be releasing last&#8230;  So for all of you who&#8217;ve helped me out by sending me suggestions and notifying me of errors and sticking with it&#8230;  Just wanted to <strong>say sorry about that, and thanks for all the great ideas.. </strong> Well, I&#8217;ve been sticking with it as well believe it our not.  I manage to get free days once in a while, and then its <strong>time to jam</strong>.</p>
<p>I&#8217;ve used just about every CMS/Blog/Forum/Trac/Gallery/etc) and really didn&#8217;t like a lot of the way they coded&#8230;  I could use php but I didn&#8217;t KNOW php.. so I&#8217;ve had to learn php also, and it was tough to learn the advanced class usage and all the other language specific (but similar) constructs for php.  It was especially difficult (but fun and challenging) to program so as to be compatible with php4 and php5 (Such is WordPress).    But I kept at it, and soon you can decide for yourself what to make of it.</p>
<p>I can code in plenty of languages (bash, lua, windows .bat and vbs,  ocaml, big fan of all things shell) and can work my way through C and even sorta somewhat with assembly.  Assembly is the hardest, by far,  I&#8217;m into easy and powerful languages like Python, Javascript, perl, php, ruby, and CGI. I&#8217;ve used PHP for a long time to do various things,  but never to build software projects like this.  Once I noticed WordPress&#8217;s core .php files and the excellent programming I wanted to try and learn hot to do it.   The WordPress code is some of the best I&#8217;ve seen.  It appears the way they built it was planned, and not just dreamt up while typing that I can&#8217;t help but do.    Every time I read through the core code I learn a new trick or very nice way to do something.  Those guys are really good, and I think WordPress is going to dominate for a long long time.</p>
<h2>The Strategy</h2>
<p>The Password Protection (passpro) plugin has a lot of complex stuff going on, especially for a newbie to PHP and WordPress like me, so after refactoring the whole thing at least 5 times I decided to modify my approach, and wrote the AskApache Google 404 Plugin as a way to practice on a simpler piece of code, while at the same time providing a plugin of value.   Eventually I stopped thinking I could just code the whole thing in one sit-down with a stream-of-consciousness, and had to instead modularize the code and focus in on each part before moving to the next (I go without a plan because its fun, just not the most productive, but again, I&#8217;m not a programmer in the scientific sense.).</p>
<p>So I decided I had to really learn how WordPress Plugins work, filters, hooks, actions, and basically comfortability at reverse-engineering code, (Im a beginner for the last time), and so with the upcoming release of the AskApache Google 404 Plugin I have succeeded in making an incredibly stable plugin.  That way I only have to worry about what the aapasspro plugin is doing, instead of trying to fit it into a framework.  </p>
<h2>AskApache Google 404 Upgrade</h2>
<p>I think its rather unusual to develop a nice plugin like this 404 handler merely for the purpose of improving upon another plugin, but hey it worked.  As of <em>08/03/2009 14:06PM EST</em> I have about 1 hour left of finishing touches to release this upgrade.  But as you cantell by my badly edited posts, I don&#8217;t have a lot of time to myself.  An hour here and there is about it.  So it could be up to 2 weeks before I actually have the time to commit the release to the repo.  On a sidenote, have you checked out <a href="http://windows7news.com/" rel="nofollow"  title="Windows 7 News">Windows 7 News</a>?  I&#8217;ve been contracted to do some technical work for them and thought they had an excellent site.</p>
<p><a href="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss1.png" rel="nofollow" ><img src="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss1-344x350.png" alt="An AskApache Plugin Upgrade to Rule them All" title="askapache-google-upgrade-ss1" width="344" height="350" class="alignnone size-medium wp-image-3139" /></a></p>
<p><a href="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss2.png" rel="nofollow" ><img src="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss2-293x350.png" alt="An AskApache Plugin Upgrade to Rule them All" title="askapache-google-upgrade-ss2" width="293" height="350" class="alignnone size-medium wp-image-3138" /></a></p>
<p>But keep in mind, the 404 PLugin is just where I practice for the passpro plugin, which truly does have features that no other software like it has ever had.  I understand the technology behind this plugin, and know it would really have a great impact on improving the Web (esp. WordPress) for all of us, I&#8217;ve just had to learn how to make it.</p>
<h2>AskApache Password Protection</h2>
<p>Probably still a couple weeks away, this plugin is the ultimate culmination of apache hackers dreams, at least those on shared servers (who may be interested in learning how to bypass security of said servers)..  So this is something I have much too fun with doing what I like to do.. network/protocol-level security.  I&#8217;ve examined the source code for many software packages that I use or have used to audit a server&#8217;s security, and this simple php plugin in most instances can enumerate with accuraccy most of the server&#8217;s setup in about a minute.  The catch (and the file permission problems I had to find a workaround too) is that this software is launched on the server, not remotely against the server.</p>
<p>Some of the software I examined was whiskers, nessus, nmap, hping, mozilla source, wireshark, ncftp, netcat, etc..  The closest comparison to the socket-level class I&#8217;ve hacked together to those is wireshark.  Except that wireshark only interprets (captures) the data passing over the wire, while this class does that and in fact sends and receives the data like netcat or nmap.  Its really more similar to metasploit, and can easily be used to send hex, binary, ascii, or any type of payload to the remote or local host.</p>
<h2>The Upgrades Begin</h2>
<p>Well I started working on them a long time ago.  Both the Password Protection plugin and the Google 404 plugin needed serious work.   And I finally have it all figured out.  Essentially I would work on one and finish an upgrade, but I just wasn&#8217;t happy with it and I wold start all over again, refactoring the code.   So as I put the finishing touches on those 2 plugins keep an eye out.  They are major upgrades.   I was able to meet all the goals I had for them, and came up with a lot of more improvements during the process.One of the main things I needed was a socket-level class to perform all kinds of checks and tests on.  I need this also for my crazy cache plugin, which my blog is currently using ,  and I have a 2 more really nice pplugins I use that also needed  access to a network class.  I wrote about what I was doing with fsockopen, and I&#8217;ve been improving on that example ever since.  I use this class to do some really powerful and exciting stuff, but you&#8217;ll see it soon enough.  As an indication of &#8216;getting it right&#8217; for the Password Protection plugin, the plugin will now work on Windows, Apache, IIS, Lighthttpd, and will even work running on a blackberry web server.  So now everyone using wordpress can at least get some security()</p>
<p class="enote">Many of the the other improvements focus on using the fsockopen class and .htaccess tricks to basically enumerate and discover all the different capabilities of your particular server;  That way you can learn about all the features and security that are possible for your specific server, and the securty modules wi8ll be geared for that as well.  FINALLY this plugin is going to be stable, and I just cant wait to see how people react when they learn all great capability their Apache-based Server has that they didn&#8217;t have a clue about.   Its amazing in that sense, and hackers will love theh way it works.. but your server admins will love it even more because its entirely 100% focused on helping you to set your site up (if you have Apache) to keep spammers out, to keep virii-serving robots and their log-hogging exploit requests and CPU/Mem robiing 404 errors off of your servers for real.  This will have a noticeable affect to whoever is running the server.   As you can tell.. I am pumped!</br></p>
<hr class="C" />
Apache is easy to configure and use, but only when you have root access.  Most people on shared and private hosting aren&#8217;t even able to view the main config file, let alone execute the Apache binaries to see what features are available and what configuration is being used.<br class="C" /></p>
<p>Apache can only be influenced by the main server configs and by .htaccess files.  Not by php, not by perl, and the main configs are almost never accessible to the masses.  But .htaccess files are.  And many hosting providers allow and enable .htaccess files, a configuration file for your web server.  The advanced features and capabilities of Apache were out of reach for most of us, it just wasn&#8217;t possible to enumerate or access, and most hosting providers are infamous for their lack of .htaccess (customer) support.  This plugin goes around those problems to give the power back to the people.<br class="C" /></p>
<p>y creating custom .htaccess files containing unpublished .htaccess tricks and techniques and combining that with the use of socket-level networking from WordPress (PHP) using <a href="http://www.askapache.com/php/fsockopen-socket.html">fsockopen</a>, we can effectively enumerate and discover an incredible amount of features and settings you will be able to control and use with this plugin.</p>
<p>Here are a few examples of the capabilities of this plugin, some of which I believe no other software can do..  <em>(Open source free to copy!)</em>.</p>
<ol>
<li>Current Version of Apache (<strong>Down to the API Version</strong>)</li>
<li>List of <strong>ALL Modules currently enabled</strong> by Apache (Such as Mod_Rewrite)</li>
<li>List of <strong>ALL Directives enabled by EACH enabled Module.</strong></li>
<li>Enumerate .htaccess Overrides, Context Permissions</li>
<li>Test for any builtin Handlers (like the <a href="http://uploads.askapache.com/2009/07/apache-server-status.png" rel="nofollow" >status handler screenshot</a>)</li>
<li>Configure SSI (<a href="http://www.askapache.com/htaccess/advanced-htaccess-ssi.html#htaccess-ssi-security">http://www.askapache.com/htaccess/advanced-htaccess-ssi.html#htaccess-ssi-security</a>)</li>
</ol>
<blockquote cite="http://www.askapache.com/htaccess/password-protection-plugin-status.html"><div class="inote"><cite><a href="http://www.askapache.com/htaccess/password-protection-plugin-status.html"></a></cite>
<p><strong>March 1, 2009</strong><br /><strong>I would focus on the method that WordPress uses</strong>.  The code they have now (2.8 bleeding-edge) still isn&#8217;t where it needs to be, but this is some difficult stuff and <strong>they have a brilliant start, it&#8217;ll work.. just a question of when</strong>.</p>
<p><a href="http://uploads.askapache.com/2009/03/apache-security-model-tall1.png" rel="nofollow" class="IFL" ><img src="http://uploads.askapache.com/2009/03/apache-security-model-tall1-250x123.png" alt="Apache Security Model - In Color" title="apache-security-model-wide" width="250" height="123" /></a><strong>The main issue</strong> with the password protection plugin working for some people and not others is due to <a href="http://www.askapache.com/security/chmod-stat.html"title="detailed file permission article" >file permission configurations</a>.  The plugin attempts to write/modify files in your blog&#8217;s root directory.<br class="C" /></p>
</div>
</blockquote>
<hr class="C" />
<blockquote cite="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"><div class="inote"><cite><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"></a></cite>
<p><strong>November 05, 2008</strong><br />To make a long story short, I downloaded each major release of the apache httpd source code starting at version 1.3.0 and finishing with version 2.2.11, I then compiled each version and built a HTTPD from source for all these apache versions.</p>
<div>
<div style="width:100px;overflow:hidden;float:left;">
<ul>
<li>1.3.0</li>
<li>1.3.1</li>
<li>1.3.11</li>
<li>1.3.12</li>
<li>1.3.14</li>
<li>1.3.17</li>
<li>1.3.19</li>
<li>1.3.2</li>
<li>1.3.20</li>
<li>1.3.22</li>
<li>1.3.23</li>
<li>1.3.24</li>
<li>1.3.27</li>
<li>1.3.28</li>
</ul>
</div>
<div style="width:100px;overflow:hidden;float:left;">
<ul>
<li>1.3.29</li>
<li>1.3.3</li>
<li>1.3.31</li>
<li>1.3.32</li>
<li>1.3.33</li>
<li>1.3.34</li>
<li>1.3.35</li>
<li>1.3.36</li>
<li>1.3.37</li>
<li>1.3.39</li>
<li>1.3.4</li>
<li>1.3.41</li>
<li>1.3.6</li>
<li>1.3.9</li>
</ul>
</div>
<div style="width:100px;overflow:hidden;float:left;">
<ul>
<li>2.0.35</li>
<li>2.0.36</li>
<li>2.0.39</li>
<li>2.0.40</li>
<li>2.0.42</li>
<li>2.0.43</li>
<li>2.0.44</li>
<li>2.0.45</li>
<li>2.0.46</li>
<li>2.0.47</li>
<li>2.0.48</li>
<li>2.0.49</li>
<li>2.0.50</li>
<li>2.0.51</li>
</ul>
</div>
<div style="width:150px;overflow:hidden;float:left;">
<ul>
<li>2.0.52</li>
<li>2.0.53</li>
<li>2.0.54</li>
<li>2.0.55</li>
<li>2.0.58</li>
<li>2.0.59</li>
<li>2.0.61</li>
<li>2.0.63</li>
<li>2.1.3-beta</li>
<li>2.1.6-alpha</li>
<li>2.1.7-beta</li>
<li>2.1.8-beta</li>
<li>2.1.9-beta</li>
</ul>
</div>
<div style="width:100px;overflow:hidden;float:left;">
<ul>
<li>2.2.0</li>
<li>2.2.10</li>
<li>2.2.2</li>
<li>2.2.3</li>
<li>2.2.4</li>
<li>2.2.6</li>
<li>2.2.8</li>
<li>2.2.9</li>
<li><strong>2.2.10</strong></li>
<li><strong>2.2.11</strong></li>
</ul>
</div>
<p><br class="C" /></div>
<p>Then I went through each version and determined the compatible modules for that version, and I&#8217;m pretty confident that I was also able to find each and every directive allowed by the compatible modules for that version (including core directives).  See <a href="http://www.askapache.com/htaccess/htaccess.html#htaccess-directives">.htaccess directive list</a>.  Basically I can now test a server using a variety of methods and determine almost 100% accurately what version of Apache (down to the API) is running, what modules (and versions) are enabled, and each and every directive that is allowed or disallowed for that version.  So this is so awesome because now we can enable all sorts of additional security features.</p>
</div>
</blockquote>
<hr class="C" />
<blockquote cite="http://www.askapache.com/htaccess/htaccess.html#htaccess-modules"><p><cite><a href="http://www.askapache.com/htaccess/htaccess.html#htaccess-modules">Htaccess enabled Modules</a></cite>
<p>Here are most of the modules that come with Apache.  Each one can have new commands that can be used in .htaccess file scopes.</p>
<p><a href="http://www.askapache.com/servers/mod_actions.c.html">mod_actions</a>, <a href="http://www.askapache.com/servers/mod_alias.c.html">mod_alias</a>, <a href="http://www.askapache.com/servers/mod_asis.c.html">mod_asis</a>, <a href="http://www.askapache.com/servers/mod_auth_basic.c.html">mod_auth_basic</a>, <a href="http://www.askapache.com/servers/mod_auth_digest.c.html">mod_auth_digest</a>, <a href="http://www.askapache.com/servers/mod_authn_anon.c.html">mod_authn_anon</a>, <a href="http://www.askapache.com/servers/mod_authn_dbd.c.html">mod_authn_dbd</a>, <a href="http://www.askapache.com/servers/mod_authn_dbm.c.html">mod_authn_dbm</a>, <a href="http://www.askapache.com/servers/mod_authn_default.c.html">mod_authn_default</a>, <a href="http://www.askapache.com/servers/mod_authn_file.c.html">mod_authn_file</a>, <a href="http://www.askapache.com/servers/mod_authz_dbm.c.html">mod_authz_dbm</a>, <a href="http://www.askapache.com/servers/mod_authz_default.c.html">mod_authz_default</a>, <a href="http://www.askapache.com/servers/mod_authz_groupfile.c.html">mod_authz_groupfile</a>, <a href="http://www.askapache.com/servers/mod_authz_host.c.html">mod_authz_host</a>, <a href="http://www.askapache.com/servers/mod_authz_owner.c.html">mod_authz_owner</a>, <a href="http://www.askapache.com/servers/mod_authz_user.c.html">mod_authz_user</a>, <a href="http://www.askapache.com/servers/mod_autoindex.c.html">mod_autoindex</a>, <a href="http://www.askapache.com/servers/mod_cache.c.html">mod_cache</a>, <a href="http://www.askapache.com/servers/mod_cern_meta.c.html">mod_cern_meta</a>, <a href="http://www.askapache.com/servers/mod_cgi.c.html">mod_cgi</a>, <a href="http://www.askapache.com/servers/mod_dav.c.html">mod_dav</a>, <a href="http://www.askapache.com/servers/mod_dav_fs.c.html">mod_dav_fs</a>, <a href="http://www.askapache.com/servers/mod_dbd.c.html">mod_dbd</a>, <a href="http://www.askapache.com/servers/mod_deflate.c.html">mod_deflate</a>, <a href="http://www.askapache.com/servers/mod_dir.c.html">mod_dir</a>, <a href="http://www.askapache.com/servers/mod_disk_cache.c.html">mod_disk_cache</a>, <a href="http://www.askapache.com/servers/mod_dumpio.c.html">mod_dumpio</a>, <a href="http://www.askapache.com/servers/mod_env.c.html">mod_env</a>, <a href="http://www.askapache.com/servers/mod_expires.c.html">mod_expires</a>, <a href="http://www.askapache.com/servers/mod_ext_filter.c.html">mod_ext_filter</a>, <a href="http://www.askapache.com/servers/mod_file_cache.c.html">mod_file_cache</a>, <a href="http://www.askapache.com/servers/mod_filter.c.html">mod_filter</a>, <a href="http://www.askapache.com/servers/mod_headers.c.html">mod_headers</a>, <a href="http://www.askapache.com/servers/mod_ident.c.html">mod_ident</a>, <a href="http://www.askapache.com/servers/mod_imagemap.c.html">mod_imagemap</a>, <a href="http://www.askapache.com/servers/mod_include.c.html">mod_include</a>, <a href="http://www.askapache.com/servers/mod_info.c.html">mod_info</a>, <a href="http://www.askapache.com/servers/mod_log_config.c.html">mod_log_config</a>, <a href="http://www.askapache.com/servers/mod_log_forensic.c.html">mod_log_forensic</a>, <a href="http://www.askapache.com/servers/mod_logio.c.html">mod_logio</a>, <a href="http://www.askapache.com/servers/mod_mem_cache.c.html">mod_mem_cache</a>, <a href="http://www.askapache.com/servers/mod_mime.c.html">mod_mime</a>, <a href="http://www.askapache.com/servers/mod_mime_magic.c.html">mod_mime_magic</a>, <a href="http://www.askapache.com/servers/mod_negotiation.c.html">mod_negotiation</a>, <a href="http://www.askapache.com/servers/mod_proxy.c.html">mod_proxy</a>, <a href="http://www.askapache.com/servers/mod_proxy_ajp.c.html">mod_proxy_ajp</a>, <a href="http://www.askapache.com/servers/mod_proxy_balancer.c.html">mod_proxy_balancer</a>, <a href="http://www.askapache.com/servers/mod_proxy_connect.c.html">mod_proxy_connect</a>, <a href="http://www.askapache.com/servers/mod_proxy_ftp.c.html">mod_proxy_ftp</a>, <a href="http://www.askapache.com/servers/mod_proxy_http.c.html">mod_proxy_http</a>, <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite</a>, <a href="http://www.askapache.com/servers/mod_setenvif.c.html">mod_setenvif</a>, <a href="http://www.askapache.com/servers/mod_speling.c.html">mod_speling</a>, <a href="http://www.askapache.com/servers/mod_ssl.c.html">mod_ssl</a>, <a href="http://www.askapache.com/servers/mod_status.c.html">mod_status</a>, <a href="http://www.askapache.com/servers/mod_substitute.c.html">mod_substitute</a>, <a href="http://www.askapache.com/servers/mod_unique_id.c.html">mod_unique_id</a>, <a href="http://www.askapache.com/servers/mod_userdir.c.html">mod_userdir</a>, <a href="http://www.askapache.com/servers/mod_usertrack.c.html">mod_usertrack</a>, <a href="http://www.askapache.com/servers/mod_version.c.html">mod_version</a>, <a href="http://www.askapache.com/servers/mod_vhost_alias.c.html">mod_vhost_alias</a></p>
</blockquote>
<hr class="C" />
<hr class="C" />
<h2>Debugging HTTP protocol</h2>
<p>Check this out!  I&#8217;m particularly happy about this feature, which outputs an exact trace of any requests made by the plugin (such as during the testing phase) by saving the actual raw data sent out on the wire using fsockopen, RX and TX.  This is useful for a number of reasons, viewing your headers, finding Redirect Loops, testing RewriteRules, and following the request hop-by-hop for debugging.  The below example shows 2 requests for 2 URIs.  The first URI is protected using Digest Authentication, the 2nd shows Basic.</p>
<pre> ______________
|  RAW TRACE   |
==================================================================================================================================
GET /htaccess/index.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
&nbsp;
HTTP/1.1 401 Authorization Required
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
WWW-Authenticate: Digest realm=&quot;do or die&quot;, nonce=&quot;03328f3ec7c7b&quot;, algorithm=MD5, domain=&quot;/&quot;, qop=&quot;auth&quot;
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 882
Connection: close
Content-Type: text/html; charset=UTF-8
&nbsp;
GET /htaccess/index.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
Authorization: Digest username=&quot;test&quot;,realm=&quot;do or die&quot;,nonce=&quot;03328f3ec7c7b&quot;,uri=&quot;/htaccess/index.txt?testing=query&quot;,
cnonce=&quot;82d057852a9dc497&quot;,nc=00000001,algorithm=MD5,response=&quot;9d476e9ea3&quot;,qop=&quot;auth&quot;
&nbsp;
HTTP/1.1 200 OK
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
Authentication-Info: rspauth=&quot;9051b01ee26dd62b3e2b40dada694f45&quot;, cnonce=&quot;82d057852a9dc497&quot;, nc=00000001, qop=auth
Last-Modified: Tue, 21 Jul 2009 23:56:00 GMT
Accept-Ranges: bytes
Cache-Control: max-age=3600
Expires: Wed, 22 Jul 2009 07:29:58 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 27
Connection: close
Content-Type: text/plain; charset=UTF-8
&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;&#96;`
&nbsp;
 ______________
|  RAW TRACE   |
==================================================================================================================================
GET /htaccess/po.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
&nbsp;
HTTP/1.1 401 Authorization Required
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
WWW-Authenticate: Basic realm=&quot;Po Pimping&quot;
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 878
Connection: close
Content-Type: text/html; charset=UTF-8
&nbsp;
GET /htaccess/po.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
Authorization: Basic adfAGAltcA==
&nbsp;
HTTP/1.1 200 OK
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 05:54:39 GMT
Accept-Ranges: bytes
Cache-Control: max-age=3600
Expires: Wed, 22 Jul 2009 07:29:58 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 27
Connection: close
Content-Type: text/plain; charset=UTF-8
&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;`&#96;&#96;`</pre>
<h2>.htaccess Directives</h2>
<p>AcceptFilter, AcceptMutex, AcceptPathInfo, AccessFileName, Action, AddAlt, AddAltByEncoding, AddAltByType, AddCharset, AddDefaultCharset, AddDescription, AddEncoding, AddHandler, AddIcon, AddIconByEncoding, AddIconByType, AddInputFilter, AddLanguage, AddModuleInfo, AddOutputFilter, AddOutputFilterByType, AddType, Alias, AliasMatch, AllowCONNECT, AllowEncodedSlashes, AllowOverride, Anonymous, Anonymous_Authoritative, Anonymous_LogEmail, Anonymous_MustGiveEmail, Anonymous_NoUserID, Anonymous_NoUserId, Anonymous_VerifyEmail, AssignUserId, AuthAuthoritative, AuthBasicAuthoritative, AuthBasicProvider, AuthDBDUserPWQuery, AuthDBDUserRealmQuery, AuthDBM, AuthDBMAuthoritative, AuthDBMGroupFile, AuthDBMType, AuthDBMUserFile, AuthDefaultAuthoritative, AuthDigestAlgorithm, AuthDigestDomain, AuthDigestFile, AuthDigestGroupFile, AuthDigestNcCheck, AuthDigestNonceFormat, AuthDigestNonceLifetime, AuthDigestProvider, AuthDigestQop, AuthDigestShmemSize, AuthGroupFile, AuthLDAPAuthzEnabled, AuthLDAPBindDN, AuthLDAPBindON, AuthLDAPBindPassword, AuthLDAPCharsetConfig, AuthLDAPCompareDNOnServer, AuthLDAPDereferenceAliases, AuthLDAPEnabled, AuthLDAPFrontPageHack, AuthLDAPGroupAttribute, AuthLDAPGroupAttributeIsDN, AuthLDAPRemoteUserAttribute, AuthLDAPRemoteUserIsDN, AuthLDAPStartTLS, AuthLDAPURL, AuthLDAPUrl, AuthName, AuthType, AuthUserFile, AuthzDBMAuthoritative, AuthzDBMType, AuthzDefaultAuthoritative, AuthzGroupFileAuthoritative, AuthzLDAPAuthoritative, AuthzOwnerAuthoritative, AuthzUserAuthoritative, BS2000Account, BalancerMember, BrowserMatch, BrowserMatchNoCase, BufferedLogs, CGIMapExtension, CacheDefaultExpire, CacheDirLength, CacheDirLevels, CacheDisable, CacheEnable, CacheExpiryCheck, CacheFile, CacheForceCompletion, CacheGcClean, CacheGcDaily, CacheGcInterval, CacheGcMemUsage, CacheGcUnused, CacheIgnoreCacheControl, CacheIgnoreHeaders, CacheIgnoreNoLastMod, CacheLastModifiedFactor, CacheMaxExpire, CacheMaxFileSize, CacheMaxStreamingBuffer, CacheMinFileSize, CacheNegotiatedDocs, CacheRoot, CacheSize, CacheStoreNoStore, CacheStorePrivate, CacheTimeMargin, CharsetDefault, CharsetOptions, CharsetSourceEnc, CheckCaseOnly, CheckSpelling, ChildPerUserId, ContentDigest, CookieDomain, CookieExpires, CookieLog, CookieName, CookieStyle, CookieTracking, CoreDumpDirectory, CustomLog, DAV, DAVDepthInfinity, DAVGenericLockDB, DAVMinTimeout, DBDExptime, DBDKeep, DBDMax, DBDMin, DBDParams, DBDPersist, DBDPrepareSQL, DBDriver, Dav, DavDepthInfinity, DavGenericLockDB, DavLockDB, DavMinTimeout, DefaultIcon, DefaultLanguage, DefaultType, DeflateBufferSize, DeflateCompressionLevel, DeflateFilterNote, DeflateMemLevel, DeflateWindowSize, Directory, DirectoryIndex, DirectoryMatch, DirectorySlash, DocumentRoot, DumpIOInput, DumpIOOutput, EnableExceptionHook, EnableMMAP, EnableSendfile, ErrorDocument, ErrorLog, Example, ExpiresActive, ExpiresByType, ExpiresDefault, ExtFilterDefine, ExtFilterOptions, ExtendedStatus, FancyIndexing, FileETag, Files, FilesMatch, FilterChain, FilterDeclare, FilterProtocol, FilterProvider, FilterTrace, ForceLanguagePriority, ForceType, ForensicLog, GprofDir, GracefulShutdownTimeout, Group, Header, HeaderName, HostNameLookups, HostnameLookups, ISAIPFakeAsync, ISAPIAppendLogToErrors, ISAPIAppendLogToQuery, ISAPICacheFile, ISAPIFakeAsync, ISAPILogNotSupported, ISAPIReadAheadBuffer, IdentityCheck, IdentityCheckTimeout, IfDefine, IfModule, IfVersion, ImapBase, ImapDefault, ImapMenu, Include, IndexIgnore, IndexOptions, IndexOrderDefault, IndexStyleSheet, KeepAlive, KeepAliveTimeout, LDAPCacheEntries, LDAPCacheTTL, LDAPCertDBPath, LDAPConnectionTimeout, LDAPOpCacheEntries, LDAPOpCacheTTL, LDAPSharedCacheFile, LDAPSharedCacheSize, LDAPTrustedClientCert, LDAPTrustedGlobalCert, LDAPTrustedMode, LDAPVerifyServerCert, LanguagePriority, Limit, LimitExcept, LimitInternalRecursion, LimitRequestBody, LimitRequestFields, LimitRequestFieldsize, LimitRequestLine, LimitXMLRequestBody, Listen, ListenBacklog, LoadFile, LoadModule, Location, LocationMatch, LockFile, LogFormat, LogLevel, MCacheMaxObjectCount, MCacheMaxObjectSize, MCacheMaxStreamingBuffer, MCacheMinObjectSize, MCacheRemovalAlgorithm, MCacheSize, MMapFile, MaxClients, MaxKeepAliveRequests, MaxMemFree, MaxRequestsPerChild, MaxSpareServers, MaxSpareThreads, MaxSpareThreadsPerChild, MaxThreads, MetaDir, MetaFiles, MetaSuffix, MimeMagicFile, MinSpareServers, MinSpareThreads, ModMimeUsePathInfo, MultiviewsMatch, NWSSLTrustedCerts, NWSSLUpgradeable, NameVirtualHost, NoProxy, NumServers, Options, PassEnv, PerlAccessHandler, PerlAuthenHandler, PerlAuthzHandler, PerlChildExitHandler, PerlChildInitHandler, PerlCleanupHandler, PerlDispatchHandler, PerlFixupHandler, PerlFreshRestart, PerlHandler, PerlHeaderParserHandler, PerlInitHandler, PerlLogHandler, PerlModule, PerlPassEnv, PerlPostReadRequestHandler, PerlRequire, PerlRestartHandler, PerlSendHeader, PerlSetEnv, PerlSetVar, PerlSetupEnv, PerlTaintCheck, PerlTransHandler, PerlTypeHandler, PerlWarn, PidFile, Port, Protocol, ProtocolEcho, Proxy, ProxyBadHeader, ProxyBlock, ProxyDomain, ProxyErrorOverride, ProxyFtpDirCharset, ProxyIOBufferSize, ProxyMatch, ProxyMaxForwards, ProxyPass, ProxyPassInterpolateEnv, ProxyPassMatch, ProxyPassReverse, ProxyPassReverseCookieDomain, ProxyPassReverseCookiePath, ProxyPreserveHost, ProxyReceiveBufferSize, ProxyRemote, ProxyRemoteMatch, ProxyRequests, ProxySet, ProxyStatus, ProxyTimeout, ProxyVia, RLimitCPU, RLimitMEM, RLimitNPROC, ReadmeName, Redirect, RedirectMatch, RedirectPermanent, RedirectTemp, RemoveCharset, RemoveEncoding, RemoveHandler, RemoveInputFilter, RemoveLanguage, RemoveOutputFilter, RemoveType, RequestHeader, Require, RewriteBase, RewriteCond, RewriteEngine, RewriteLock, RewriteLog, RewriteLogLevel, RewriteMap, RewriteOptions, RewriteRule, SSIAccessEnable, SSIEndTag, SSIErrorMsg, SSIStartTag, SSITimeFormat, SSIUndefinedEcho, SSLCACertificateFile, SSLCACertificatePath, SSLCADNRequestFile, SSLCADNRequestPath, SSLCARevocationFile, SSLCARevocationPath, SSLCertificateChainFile, SSLCertificateFile, SSLCertificateKeyFile, SSLCipherSuite, SSLCryptoDevice, SSLEngine, SSLHonorCipherOrder, SSLLog, SSLLogLevel, SSLMutex, SSLOptions, SSLPassPhraseDialog, SSLProtocol, SSLProxyCACertificateFile, SSLProxyCACertificatePath, SSLProxyCARevocationFile, SSLProxyCARevocationPath, SSLProxyCipherSuite, SSLProxyEngine, SSLProxyMachineCertificateFile, SSLProxyMachineCertificatePath, SSLProxyProtocol, SSLProxyVerify, SSLProxyVerifyDepth, SSLRandomSeed, SSLRequire, SSLRequireSSL, SSLSessionCache, SSLSessionCacheTimeout, SSLUserName, SSLVerifyClient, SSLVerifyDepth, Satisfy, ScoreBoardFile, Script, ScriptAlias, ScriptAliasMatch, ScriptInterpreterSource, ScriptLog, ScriptLogBuffer, ScriptLogLength, ScriptStock, SecureListen, SendBufferSize, ServerAdmin, ServerAlias, ServerLimit, ServerName, ServerPath, ServerRoot, ServerSignature, ServerTokens, SetEnv, SetEnvIf, SetEnvIfNoCase, SetHandler, SetInputFilter, SetOutputFilter, StartServers, StartThreads, Substitute, SuexecUserGroup, ThreadLimit, ThreadStackSize, ThreadsPerChild, TimeOut, Timeout, TraceEnable, TransferLog, TypeAuthDBMUserFile, TypesConfig, UnsetEnv, UseCanonicalName, UseCanonicalPhysicalPort, User, UserDir, VirtualDocumentRoot, VirtualDocumentRootIP, VirtualHost, VirtualScriptAlias, VirtualScriptAliasIP, Win32DisableAcceptEx, XBitHack, allow, deny, order, php_admin_flag, php_admin_value, php_flag, php_value</p>
<p class="anote">You can view the <a href="http://www.askapache.com/htaccess/htaccess-security-block-spam-hackers.html">plugins home page</a>, <a href="http://www.askapache.com/wordpress/htaccess-password-protect.html#aadl">old</a>, or <a href="http://wordpress.org/extend/plugins/askapache-password-protect/" rel="nofollow" >view it on the wordpress.org site</a>.</p>
<p><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html"></a><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html">An AskApache Plugin Upgrade to Rule them All</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP and AJAX shell console</title>
		<link>http://www.askapache.com/ajax/php-and-ajax-shell-console.html</link>
		<comments>http://www.askapache.com/ajax/php-and-ajax-shell-console.html#comments</comments>
		<pubDate>Sun, 14 Jun 2009 01:01:15 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[302 Redirect]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Htaccess]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[htaccess tutorial]]></category>
		<category><![CDATA[HTTP-EQUIV]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell console]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.askapache.com/tools/php-and-ajax-shell-console.html</guid>
		<description><![CDATA[<p><a class="IFL" id="id22" href='http://www.askapache.com/ajax/php-and-ajax-shell-console.html' title='PHP AJAX shell console'></a> Ever wanted to execute commands on your server through php? Now you can.  I'm calling this file (see below) shell.php and it allows you to run commands on your web server with the same permissions that your php executable has.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to execute commands on your server through php to mimick a shell login? <strong>Now you can.</strong>  I&#8217;m calling this file (see below) shell.php and it allows you to run commands on your web server with the same permissions that your php executable has.</p>
<p id="aaflash"><span class="v640"><span id="phpajaxshell"><span class="load">Loading Video</span><a href="http://www.askapache.com/getflash/"rel="nofollow" class="getFlash" ></a></span></span></p>
<h2>PHP for <code>shell.php</code></h2>
<p>Substitue 1.1.1.1 for your IP address.. or see below for password authentication methods.</p>
<pre>&lt;?php
 if ($_SERVER[&#039;REMOTE_ADDR&#039;] !== &#039;1.1.1.1&#039;) die();
 ob_start();
 if (!empty($_GET[&#039;cmd&#039;])){
 $ff=$_GET[&#039;cmd&#039;];
 #shell_exec($ff);
 system($ff);
 #exec($ff);
 #passthru($ff);
 }
 else {
?&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;title&gt;PHP AJAX Shell&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;var CommHis=new Array();var HisP;
function doReq(_1,_2,_3){var HR=false;if(window.XMLHttpRequest){HR=new XMLHttpRequest();if(HR.overrideMimeType){HR.overrideMimeType(&quot;text/xml&quot;);}}
else{if(window.ActiveXObject){try{HR=new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);}catch(e){try{HR=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);}
catch(e){}}}}if(!HR){return false;}HR.onreadystatechange=function(){if(HR.readyState==4){
if(HR.status==200){if(_3){eval(_2+&quot;(HR.responseXML)&quot;);}else{eval(_2+&quot;(HR.responseText)&quot;);}}}};HR.open(&quot;GET&quot;,_1,true);HR.send(null);}
function pR(rS){var _6=document.getElementById(&quot;outt&quot;);var _7=rS.split(&quot;\n\n&quot;);
var _8=document.getElementById(&quot;cmd&quot;).value;_6.appendChild(document.createTextNode(_8));
_6.appendChild(document.createElement(&quot;br&quot;));for(var _9 in _7){var _a=document.createElement(&quot;pre&quot;);
_a.style.display=&quot;inline&quot;;line=document.createTextNode(_7[_9]);_a.appendChild(line);_6.appendChild(_a);
_6.appendChild(document.createElement(&quot;br&quot;));}_6.appendChild(document.createTextNode(&quot;:-&gt; &quot;));_6.scrollTop=_6.scrollHeight;
document.getElementById(&quot;cmd&quot;).value=&quot;&quot;;}function keyE(_b){switch(_b.keyCode){
case 13:var _c=document.getElementById(&quot;cmd&quot;).value;if(_c){CommHis[CommHis.length]=_c;HisP=CommHis.length;var _d=document.location.href+&quot;?cmd=&quot;+escape(_c);
doReq(_d,&quot;pR&quot;);}break;
case 38:if(HisP&gt;0){HisP&#45;-;document.getElementById(&quot;cmd&quot;).value=CommHis[HisP];}break;
case 40:if(HisP&lt;CommHis.length-1){HisP++;document.getElementById(&quot;cmd&quot;).value=CommHis[HisP];}break;default:break;}}
&lt;/script&gt;&lt;/head&gt;&lt;body style=&quot;font-family:courier&quot;&gt;
&lt;form onsubmit=&quot;return false&quot; style=&quot;color:#3F0;background:#000;position:relative;min-height:450px;max-height:490px&quot;&gt;
&lt;div id=&quot;outt&quot; style=&quot;overflow:auto;padding:5px;height:90%;min-height:450px;max-height:490px&quot;&gt;:-&gt;&lt;/div&gt;
&lt;input tabindex=&quot;1&quot; onkeyup=&quot;keyE(event)&quot; style=&quot;color:#FFF;background:#333;width:100%;&quot; id=&quot;cmd&quot; type=&quot;text&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php } ?&gt;</pre>
<h2>Read this</h2>
<p><strong>Note</strong>:  The history feature works by remembering the last commands that you typed.. Access them by pressing the up or down arrows on your keyboard.</p>
<p>This is not an interactive session, so you cannot cd to a directory and then do stuff in that directory..  You may however be able to do stuff like <code>/bin/bash -c "cd ../../;mv this there;ls -la;"</code> or you could try exporting your current dir or something..</p>
<p>Writing shell scripts and serving them on your web server works by renaming the file.sh to file.cgi and chmodding it to 750 or +x.   Also make sure you try <code>dos2unix -dv file.cgi</code> If you can&#8217;t get it to work.. </p>
<h3>Example shell script as cgi</h3>
<pre>#!/bin/sh
export MYBNAME=`date +%mx%dx%y-%Hx%M.tgz`
tar -czf ${HOME}/backups/${MYBNAME} ${HOME}/site1/
exit 0;</pre>
<h2>Locking Down Access to your shell.php</h2>
<p>Thanks to the comment by Andrew Ramsden, Here are a couple ways to secure your shell.php file so that only you can run this script.</p>
<h3>Secure your remote shell by adding this to your shell.php</h3>
<p>Add this line to the very top of your shell.php file to make sure that only you can access this script.  Everyone else sees a blank screen.</p>
<pre>if ($_SERVER[&#039;REMOTE_ADDR&#039;] !== &#039;1.1.1.1&#039;) die();</pre>
<h3>Secure your remote shell with htaccess</h3>
<p>This only allows access from IP 1.1.1.1 and redirects everyone else.  See <a href="http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html#using-allow-directive-in-apache" title="allow directive in apache htaccess">Using the Allow Directive in Apache htaccess</a> for more info.</p>
<pre>Order deny,allow
Deny from all
Allow from 1.1.1.1
ErrorDocument 403 http://www.askapache.com</pre>
<h2>Secure your remote shell with mod_rewrite and htaccess</h2>
<p>Based on the code from <a href="http://www.askapache.com/htaccess/htaccess-for-webmasters.html#redirect-except-1-ip-mod-rewrite" title="Apache htaccess tutorial">htaccess article</a>  This only allows access from user with IP of 1.1.1.1 and redirects everyone else.</p>
<pre>RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1\.1\.1\.1
RewriteRule .* http://www.askapache.com [R=302,L]</pre>
<p><a href="http://www.askapache.com/ajax/php-and-ajax-shell-console.html"></a><a href="http://www.askapache.com/ajax/php-and-ajax-shell-console.html">PHP and AJAX shell console</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/ajax/php-and-ajax-shell-console.html/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Advanced Htaccess Demo/Example using Cookies, Headers, Rewrites</title>
		<link>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html</link>
		<comments>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html#comments</comments>
		<pubDate>Wed, 01 Apr 2009 03:07:53 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[htaccess rewrite]]></category>
		<category><![CDATA[htaccess tutorial]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[nsa]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=2328</guid>
		<description><![CDATA[<p><a class="IFL" id="id10" href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><strong>Whoa pretty sweet huh?</strong>  Bet you've never seen that before!  As I explain the htaccess code that achieves this, keep in mind this is merely one simple application for this code.  It's much more advanced than your basic htaccess trick, notice how this htaccess acts like a php script, very unusual..  I really wanted to share this trick after I created it for one of my clients because this is the tip of the iceberg.  Another use would be to display an alternate style sheet depending on a users theme preference.  The coolest thing about this example <acronym title="In My Humble Opinion">IMHO</acronym> is that it uses multiple advanced .htaccess ideas in order for it to work, most htaccess code on the net is very singular.  This code uses mod_headers to set the Content-Disposition header for forcing a download and uses mod_rewrite to do the rest.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"class="IFL" id="id10" ></a></p>
<p><strong>Welcome to the first generation of the new .htaccess tutorials/articles</strong>.  Basically these are articles detailing my BEST (almost) successful .htaccess experiments, meaning this is the only place on the net you&#8217;ll find this technique.  It&#8217;s home-grown .htaccess, and its some kush, good kush. Instead of just publishing my cryptic results and code in days past, whoah.. a working demo <em>and the NSA building</em>  <strong>;)</strong></p>
<p>Using the <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> makes this example, and all advanced .htaccess code easier to understand.  Well, advanced for me at least.  I know alot of AskApache visitors are some of the top gurus in many IT fields, but mostly web developers or website owners like me..   This demo is pretty self-explanatory.. Try it out to see how simple of a task this <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess trick</a> performs.  And make sure you read the whole article as this htaccess technique can be used to do a heck of a lot more than this simple demo.</p>
<h2>Set PDF Viewing Mode</h2>
<div class="cnote">
<p id="pdfi" class="BTN FL"><span class="y"><span class="t"></span><span class="text">Inline</span></span><span class="b"><span></span></span></p>
<p id="pdfa" class="BTN FL"><span class="y"><span class="t"></span><span class="text">Download</span></span><span class="b"><span></span></span></p>
<p id="pdfs" class="BTN FL"><span class="y"><span class="t"></span><span class="text">Save As</span></span><span class="b"><span></span></span></p>
<p class="FL" style="margin-left:50px;"><kbd id="pdfr" style="border:2px solid #BFBFCC;padding:10px;line-height:1.1em;">Please make a selection, defaults to "Save As" mode.</kbd></p>
<p><br class="C" /><br />
<a href="http://www.askapache.com/storage/pdf/AskApache-Test.pdf"style="font-size:1.2em;line-height:1.2em;width:22em;" class="BTN" ><span class="y"><span class="t"></span><span class="text">View PDF using selected mode &raquo;</span></span><span class="b"><span></span></span></a>
</div>
<p>Whoa pretty sweet huh?  Bet you&#8217;ve never seen that before!  As I explain the htaccess code that achieves this, keep in mind this is merely one simple application for this code.  It&#8217;s much more advanced than your basic htaccess trick, notice how this htaccess acts like a php script, very unusual..  I really wanted to share this trick after I created it for one of my clients because this is the tip of the iceberg.  Another use would be to display an alternate style sheet depending on a users theme preference.  The coolest thing about this example <acronym title="In My Humble Opinion">IMHO</acronym> is that it uses multiple advanced .htaccess ideas in order for it to work, most htaccess code on the net is very singular.  This code uses mod_headers to set the Content-Disposition header for forcing a download and uses mod_rewrite to:</p>
<ol>
<li>Send different Content-Type headers</li>
<li>Check the value of a cookie</li>
<li>Set environment variables for use later by mod_headers header directive</li>
</ol>
<h2>What&#8217;s Going On</h2>
<p>There are 3 different ways for a server to send a pdf file in response to a request for one.  This causes 3 different ways to open/view the pdf file in the clients browser.</p>
<ol>
<li>The browser display&#8217;s a <strong>&#8220;Save File As&#8221;</strong> dialog, allowing you to save the file or open.</li>
<li>The browser opens the pdf file <strong>&#8220;Inline&#8221;</strong>, opening the pdf file in the browser like a web page.</li>
<li>The browser &#8220;<strong>Downloads</strong>&#8221; the pdf file automatically as an &#8220;<strong>Attachment</strong>&#8221; and then causes an external pdf reader program like adobe reader to open the file.</li>
</ol>
<p>Some people prefer to have the option of saving the file to view later, some prefer opening it with an external program, and some just like the pdf file to load right in the browser&#8230;  The point is that by using .htaccess, we can let them choose any of the 3 methods and save their preference for all further pdf files requested from our site by that user.</p>
<h2>How It Works</h2>
<p>When you click on one of the 3 demo buttons above, &#8220;Inline&#8221;, &#8220;Save As&#8221;, or &#8220;Download&#8221;, a cookie named <code>askapache_pdf</code> is saved in your browser using the javascript below, with the value being set to which button you clicked.  Then when you request the pdf file the .htaccess code below uses mod_rewrite to read the value of the askapache_pdf cookie, and depending on which was your preference it will send alternate HTTP Headers that control how your browser handles the file.</p>
<h3>Htaccess Demo File</h3>
<p>For the demo I created the folder /storage/pdf/ and this is the .htaccess file at /storage/pdf/.htaccess</p>
<pre>#
# The default Content-Type for .pdf files
# This will make .pdf files default Content-Type header have
# the value &#039;application/pdf&#039; - but the default can be overridden by
# using RewriteRule with the [T=&#039;different/type&#039;]
#
AddType application/pdf .pdf
&nbsp;
#
# Turn on the rewrite engine
# if its already on you dont need this
#
RewriteEngine On
&nbsp;
#
# Skip RewriteRules if not .pdf request, like autoindexing
# The next [2] RewriteRule directives are specific for .pdf files
# so if the filename requested does not end in .pdf
# then the [S=2] instructs the next 2 RewriteRule
# directives to be completely skipped
#
RewriteRule !.*\.pdf$ - [S=2]
&nbsp;
#
# The first RewriteCond checks to see if the askapache_pdf cookie
# is NOT set.  The second RewriteCond checks to see if the askapche_pdf
# cookie has the value of s, which is the value corresponding to
# someone clicking the &quot;Save As&quot; button.
#
# The [NC,OR] flag means that if the cookie askapache_pdf does not
# exist, OR (next cond) if the askapache_pdf cookie does exist and is set to &#039;s&#039;
# then process the RewriteRule.  If neither cond is true the rewriterule is skipped.
#
# If one of the RewriteCond is true, then the RewriteRule is processed.
# The RewriteRule applies to any/all requests (.*) but doesn&#039;t rewrite anything (-)
# This RewriteRule sets an Apache environment variable ASKAPACHE_PDFS to have the
# value of 1 if either rewritecond is true.  The variable can be checked by any directives
# following the rewriterule in the whole htaccess file.  The ASKAPACHE_PDFS ends in S
# because if this variable exists then it means the users preference is &#039;Save As&#039;
#
# Notice that if the user requested the pdf file without selecting a preference
# i.e. no cookie exists, then the ASKAPACHE_PDFS variable is still set.
# This just lets us pick the default preference for them, in this example the
# default is &#039;Save As&#039;
#
RewriteCond %{HTTP_COOKIE} !^.*askapache_pdf.*$ [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=s.*$ [NC]
RewriteRule .* - [E=ASKAPACHE_PDFS:1]
&nbsp;
#
# The RewriteCond checks the askapache_pdf cookie for the value &#039;a&#039;
# which &#039;a&#039; represents &#039;Download&#039;
#
# If the cookies value is &#039;a&#039; then the RewriteRule overrides the default
# Content-Type from &#039;application/pdf&#039; set with AddType earlier, to
# &#039;application/octet-stream&#039;, which is a special content-type that tells the browser
# that the file cannot be loaded by the browser &#039;Inline&#039;, but must be saved
# which will be opened by an external viewer depending on browser
#
RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=a.*$
RewriteRule .* - [T=application/octet-stream]
&nbsp;
#
# This is superfly.  If the cookie/users-preference was &#039;Save As&#039; (s)
# then the RewriteRule above the last one set the environment
# variable ASKAPACHE_PDFS to have the value 1.  The Header directive here
# is ONLY processed in that variable ASKAPACHE_PDFS exists.  That is what
# the end &#039;env=ASKAPACHE_PDFS&#039; does, it is the condition that must be met or
# the Header directive is skipped.
#
# If the ASKAPACHE_PDFS environment variable set by RewriteRule does exist
# then the header directive adds the header &#039;Content-Disposition: attachment&#039; to
# the normal Response Headers.  The &#039;Content-Disposition: attachment&#039; header
# instructs your browser to present you with the &#039;Save As&#039; dialog box
# allowing you to choose whether you want to save or open
#
Header set Content-Disposition &quot;attachment&quot; env=ASKAPACHE_PDFS</pre>
<h3>Unique HTTP Headers Returned</h3>
<p>When it comes down to it, the following information is the 3 modes.  Notice each one is different, because these headers are the only thing controlling how your browser handles the file.</p>
<p>Save As Mode (askapache_pdf=s)</p>
<pre>Content-Disposition: attachment
Content-Type: application/pdf</pre>
<p>Inline Mode (askapache_pdf=i)</p>
<pre>Content-Type: application/pdf</pre>
<p>Download Mode (askapache_pdf=a)</p>
<pre>Content-Type: application/octet-stream</pre>
<h2>Javascript used by Demo</h2>
<p>The best place for javascript is quirksmode, here is a definitive article on setting, reading, parsing, etc.. <a href="http://www.quirksmode.org/js/cookies.html" rel="nofollow" title="I am a javascript cookie monster" >COOKIES</a>.</p>
<pre>  if(!gi(&#039;pdfr&#039;))return;
  var pdfr=gi(&#039;pdfr&#039;);
  var cval=getCookie(&#039;askapache_pdf&#039;);

  if(cval==&#039;i&#039;){pdfr.innerHTML=&#039;Currently set to &quot;Inline&quot;.&#039;;}
  else if(cval==&#039;a&#039;){pdfr.innerHTML=&#039;Currently set to &quot;Download&quot; mode.&#039;;}
  else if(cval==&#039;s&#039;){pdfr.innerHTML=&#039;Currently set to &quot;Save As&quot; mode.&#039;;}
&nbsp;
  addMyEvent(gi(&#039;pdfi&#039;),&quot;mousedown&quot;,function(){setCookie(&quot;askapache_pdf&quot;, &quot;i&quot;, &quot;&quot;, &quot;/&quot;, &quot;www.askapache.com&quot;); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to &quot;Inline&quot;.&#039;; return false; });
  addMyEvent(gi(&#039;pdfa&#039;),&quot;mousedown&quot;,function(){setCookie(&quot;askapache_pdf&quot;, &quot;a&quot;, &quot;&quot;, &quot;/&quot;, &quot;www.askapache.com&quot;); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to &quot;Download&quot;.&#039;; return false; });
  addMyEvent(gi(&#039;pdfs&#039;),&quot;mousedown&quot;,function(){setCookie(&quot;askapache_pdf&quot;, &quot;s&quot;, &quot;&quot;, &quot;/&quot;, &quot;www.askapache.com&quot;); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to &quot;Save As&quot;.&#039;; return false; });</pre>
<hr class="C" />
<hr class="C" />
<h2>Alternative Method &#8211; No Cookies + PHP</h2>
<p>This is what I came up with first for my client, and then while programming the php I noticed.. Hey!  I think I can do the same thing using .htaccess, which would save me on cpu/memory/potential security/etc.. but this works great too.  Though you will need to hack the code to get it working probably..</p>
<p>Note that the .htaccess rewrite code I used here used FILENAME-i.pdf or FILENAME-s.pdf to pass the preference to the pdf-dl.php script, it also worked for FILENAME.pdf?i=i</p>
<h3>pdf-dl.php</h3>
<p><?php<br />
if (<br />
  !isset($_GET['file'])<br />
  || ($f=$_GET['file'])===false<br />
  || ($fp=@fopen($f,"rb"))===false<br />
  || ($fi=pathinfo($f))===false<br />
  || ($fi['fsize']=filesize($f))===false<br />
  || strtolower($fi["extension"])!='pdf'<br />
) die('Failed');</p>
<p>ob_start();<br />
header('Accept-Ranges: bytes');<br />
header("Content-Length: {$fi['fsize']}");<br />
header('Content-Type: application/pdf');<br />
if(!isset($_GET['i'])) header("Content-Disposition: attachment; filename=\"{$fi['basename']}\"");</p>
<p>$sent = 0;<br />
while ( !feof($fp) &#038;&#038; $sent < $fi['fsize'] &#038;&#038; ($buf = fread($fp, 8192)) != '' ){<br />
  echo $buf;<br />
  $sent += strlen($buf);<br />
  flush();<br />
  ob_flush();<br />
}<br />
fclose($fp);<br />
exit;<br />
?>
</pre>
<h3>Alternate Method .htaccess</h3>
<pre>#
# Deny direct request to pdf-dl.php file
#
RewriteCond %{THE_REQUEST} ^.*pdf-dl\.php.*$ [NC]
RewriteRule .* - [F]
&nbsp;
#
# Handle PDF files named anything-i.pdf as inline
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)-i\.pdf$  /cgi-bin/pdf-dl.php?i=i&amp;file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA,S=1]
&nbsp;
#
# Handle PDF files without -i.pdf as attachments
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)\.pdf$  /cgi-bin/pdf-dl.php?file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA]</pre>
<h2>More Info</h2>
<p>The following is more information about the Content-Dispositon header and related headers, and will make you an expert at this if you read it all.. (no thanks)</p>
<h3>Interesting Reading</h3>
<p>Here is the thread of the original draft proposal for the Content-Disposition header.</p>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03620.html" rel="nofollow" >Content-Disposition Header</a>, <em>Rens Troost - 22 Jun 1993</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03629.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03630.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03631.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03635.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03641.html" rel="nofollow" >Content-Disposition Header and multipart/alternative</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03645.html" rel="nofollow" >Re: Content-Disposition Header and multipart/alternative</a>, <em>Nathaniel Borenstein</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03632.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Keith Moore</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03633.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03634.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Ed Levinson (Contractor)</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03636.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03640.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03650.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Harald Tveit Alvestrand</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03621.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Steve Dorner</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03622.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Rens Troost</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03624.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
</ul>
</li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03652.html" rel="nofollow" >Re: Content-Disposition Header</a>, <em>Carlyn M. Lowery</em></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>Intense Reading</h3>
<ul>
<li><a href="http://www2.roguewave.com/support/docs/leif/sourcepro/html/protocolsug/10-1.html" rel="nofollow" >Using the MIME Headers Effectively</a></li>
<li><a href="http://www.iana.org/assignments/mail-cont-disp" rel="nofollow" >Mail Content Disposition Values and Parameters</a></li>
<li><cite><a href="http://rfc.askapache.com/rfc1766/rfc1766.txt" rel="nofollow" >Tags for the Identification of Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1436/rfc1436.txt" rel="nofollow" >The Internet Gopher Protocol (a distributed document search and retrieval protocol)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1630/rfc1630.txt" rel="nofollow" >Universal Resource Identifiers in WWW</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1738/rfc1738.txt" rel="nofollow" >Uniform Resource Locators (URL)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1866/rfc1866.txt" rel="nofollow" >Hypertext Markup Language - 2.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1945/rfc1945.txt" rel="nofollow" >Hypertext Transfer Protocol -- HTTP/1.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2045/rfc2045.txt" rel="nofollow" >Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1123/rfc1123.txt" rel="nofollow" >Requirements for Internet Hosts -- Communication Layers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc822/rfc822.txt" rel="nofollow" >Standard for The Format of ARPA Internet Text Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1808/rfc1808.txt" rel="nofollow" >Relative Uniform Resource Locators</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1036/rfc1036.txt" rel="nofollow" >Standard for Interchange of USENET Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc977/rfc977.txt" rel="nofollow" >Network News Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2047/rfc2047.txt" rel="nofollow" >MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1867/rfc1867.txt" rel="nofollow" >Form-based File Upload in HTML</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc821/rfc821.txt" rel="nofollow" >Simple Mail Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1590/rfc1590.txt" rel="nofollow" >Media Type Registration Procedure</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc959/rfc959.txt" rel="nofollow" >File Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1700/rfc1700.txt" rel="nofollow" >Assigned Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1737/rfc1737.txt" rel="nofollow" >Functional Requirements for Uniform Resource Names</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1864/rfc1864.txt" rel="nofollow" >The Content-MD5 Header Field</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1900/rfc1900.txt" rel="nofollow" >Renumbering Needs Work</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1952/rfc1952.txt" rel="nofollow" >GZIP file format specification version 4.3</a></cite></li>
<li><cite>Improving HTTP Latency</cite></li>
<li><cite><a href="http://www.isi.edu/touch/pubs/http-perf96/" rel="nofollow" >Analysis of HTTP Performance</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1305/rfc1305.txt" rel="nofollow" >Network Time Protocol (Version 3) Specification, Implementation and Analysis</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1951/rfc1951.txt" rel="nofollow" >DEFLATE Compressed Data Format Specification version 1.3</a></cite></li>
<li><cite><a href="http://sunsite.unc.edu/mdma-release/http-prob.html" rel="nofollow" >Analysis of HTTP Performance Problems,</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1950/rfc1950.txt" rel="nofollow" >ZLIB Compressed Data Format Specification version 3.3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2069/rfc2069.txt" rel="nofollow" >An Extension to HTTP: Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2068/rfc2068.txt" rel="nofollow" >Hypertext Transfer Protocol -- HTTP/1.1</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2119/rfc2119.txt" rel="nofollow" >Key words for use in RFCs to Indicate Requirement Levels</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1806/rfc1806.txt" rel="nofollow" >Communicating Presentation Information in Internet Messages: The Content-Disposition Header</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2145/rfc2145.txt" rel="nofollow" >Use and Interpretation of HTTP Version Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2076/rfc2076.txt" rel="nofollow" >Common Internet Message Headers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2279/rfc2279.txt" rel="nofollow" >UTF-8, a transformation format of Unicode and ISO-10646</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2046/rfc2046.txt" rel="nofollow" >Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2277/rfc2277.txt" rel="nofollow" >IETF Policy on Character Sets and Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2396/rfc2396.txt" rel="nofollow" >Uniform Resource Identifiers (URI): Generic Syntax and Semantics</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2617/rfc2617.txt" rel="nofollow" >HTTP Authentication: Basic and Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2110/rfc2110.txt" rel="nofollow" >MIME E-mail Encapsulation of Aggregate Documents, such as HTML (MHTML)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2026/rfc2026.txt" rel="nofollow" >The Internet Standards Process -- Revision 3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2324/rfc2324.txt" rel="nofollow" >Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2049/rfc2049.txt" rel="nofollow" >Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2183/rfc2183.txt" rel="nofollow" >Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field</a></cite></li>
</ul>
<p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html">Advanced Htaccess Demo/Example using Cookies, Headers, Rewrites</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Htaccess SEO Trends by Google</title>
		<link>http://www.askapache.com/htaccess/htaccess-seo-trends.html</link>
		<comments>http://www.askapache.com/htaccess/htaccess-seo-trends.html#comments</comments>
		<pubDate>Sun, 29 Mar 2009 06:10:03 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[stat]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1059</guid>
		<description><![CDATA[<p><strong><span class="Gred">htaccess</span> vs. <span class="Gblue">httpd.conf</span></strong></p>
<p><a class="IFL hs hs24" href="http://www.askapache.com/htaccess/htaccess-seo-trends.html" title=".htaccess seo vs. httpd.conf seo"></a><br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<h2>How Relevant Is <span class="Gblue">.htaccess</span>?</h2>
<p><strong>Scale is based on the average worldwide traffic of htaccess in all years.</strong></p>
<p><img src="http://www.google.com/trends/viz?q=.htaccess&#038;graph=weekly_img&#038;sa=N" alt=".htaccess usage and seo" width="580" height="260" title=" apache" /><br class="C" /></p>
<h3><strong>.</strong><span class="Gred">htaccess</span> vs. <span class="Gblue">htaccess</span></h3>
<p><a href="http://google.com/trends/viz?q=.htaccess,+htaccess&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=.htaccess,+htaccess&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="comparing .htaccess and htaccess seo" title=" apache" /></a><br class="C" /></p>
<h3><span class="Gred">htaccess</span> vs. <span class="Gblue">httpd.conf</span></h3>
<p><a href="http://www.google.com/trends?q=httpd.conf%2C+.htaccess&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow"  title="htaccess vs. httpd.conf"><img src="http://www.google.com/trends/viz?q=httpd.conf,+.htaccess&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="htaccess vs. httpd.conf" title=" apache" /></a><br class="C" /></p>
<h3><span class="Gblue">mod_rewrite</span> vs. <span class="Gred">mod_security</span></h3>
<p><a href="http://google.com/trends?q=mod_rewrite%2Cmod_security&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=mod_rewrite,mod_security&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="comparing mod_rewrite and mod_security" title=" apache" /></a><br class="C" /></p>
<hr class="C" />
<h2>Web Server Comparisons</h2>
<p>Of course IIS is well-known to someone like me&#8230; but who cares about the big servers when small, light, <a href="http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servers" rel="nofollow" >super-fast servers</a> are on the rise?  See this <a href="http://en.wikipedia.org/wiki/Comparison_of_web_server_software" rel="nofollow" >Comparison of Web Servers</a>.</p>
<h3><span class="Gblue">Apache HTTP</span> vs. <span class="Gred">Windows IIS</span></h3>
<p><a href="http://www.google.com/trends?q=%22apache+HTTP%22%2C+%22windows+IIS%22&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow"  alt="Apache vs. IIS"><img src='http://www.google.com/trends/viz?q=%22apache+HTTP%22,+%22windows+IIS%22&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N' width="580" height="260" alt="Apache or Microsoft IIS" title=" apache" /></a><br class="C" /></p>
<h3><span class="Gred">Fnord</span>, Nginx, <span class="Gblue">LightHttpd</span></h3>
<p>Fnord what is going on?</p>
<p><a href="http://google.com/trends?q=lighttpd%2Cnginx%2Cfnord&#038;ctab=0&#038;geo=all&#038;date=ytd&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=lighttpd,nginx,fnord&#038;date=ytd&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="Which light server is popular" title=" apache" /></a><br class="C" /></p>
<hr class="C" />
<h2>Web Programming Comparisons</h2>
<p>An interesting look at the search engine trends of programming languages out there today&#8230;</p>
<h3>Did <span class="Gred">Ruby</span> Pass <span class="Gblue">Perl</span>!</h3>
<p>Keep in mind that Google may be interpreting &#8220;ruby&#8221; to be a precious stone&#8230; and what is a &#8220;perl&#8221; exactly?  ;)</p>
<p><a href="http://google.com/trends?q=perl%2Cruby&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=perl,+ruby&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="Ruby vs Perl Programming Language" title=" apache" /></a><br class="C" /></p>
<h3><span class="Gblue">Perl</span> vs. <span class="Gred">PHP</span>, Old Debate</h3>
<p><a href="http://google.com/trends?q=perl%2Cphp&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=perl,+php&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="Is it Perl or PHP" title=" apache" /></a><br class="C" /></p>
<hr class="C" />
<h2><span class="Gblue">SEO</span></h2>
<p>Wow. Big surpise there ;)</p>
<p><a href="http://google.com/trends?q=seo&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=seo&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="Well at least something is drastically up" title=" apache" /></a><br class="C" /></p>
<hr class="C" />
<h2><span class="Gblue">Treo</span> vs. <span class="Gred">Blackberry</span> vs. <span class="Gorange">Palm</span></h2>
<p>I love my Blackberry Curve!  I used to love my Sony Clie, and I won&#8217;t forget my many Palms!</p>
<p><a href="http://google.com/trends?q=treo%2Cblackberry%2Cpalm&#038;ctab=0&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src="http://www.google.com/trends/viz?q=treo,blackberry,palm&#038;date=all&#038;geo=all&#038;graph=weekly_img&#038;sort=0&#038;sa=N" alt="Treo vs. Blackberry vs. Palm" title=" apache" /></a><br class="C" /></p>
<hr class="C" />
<h2>AskApache WebSite</h2>
<p>Google Trends also lets you compare websites, I can&#8217;t believe its been over a year for askapache.com, thanks for stopping by!</p>
<p><a href="http://trends.google.com/websites?q=askapache.com&#038;geo=all&#038;date=all&#038;sort=0" rel="nofollow" ><img src='http://static.askapache.com/i/google-rank.png' alt='AskApache.com Google Rank' class='alignnone' title="google rank apache" /></a><br class="C" /></p>
<hr class="C" />
<h2>Google Trends &#8211; Rocks!</h2>
<p><strong>Fun, free, and helpful tool from who else?</strong><br />
<a href='http://google.com/trends'><img src="http://uploads.askapache.com/2008/07/logo-200x79.gif" alt="Google Trends by Google Labs" title="logo" width="200" height="79" /></a><br class="C" /></p>
<p><a href="http://www.askapache.com/htaccess/htaccess-seo-trends.html"></a><a href="http://www.askapache.com/htaccess/htaccess-seo-trends.html">Htaccess SEO Trends by Google</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/htaccess-seo-trends.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Password Protection Plugin Status</title>
		<link>http://www.askapache.com/htaccess/password-protection-plugin-status.html</link>
		<comments>http://www.askapache.com/htaccess/password-protection-plugin-status.html#comments</comments>
		<pubDate>Sun, 01 Mar 2009 17:39:57 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[.htaccess plugin]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[apache security]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[AskApache Password Protection]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[Fsockopen]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[nsa]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[php interpreter]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[security reasons]]></category>
		<category><![CDATA[security tips]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server config]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[Username]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1966</guid>
		<description><![CDATA[<p><strong>Enumerating Permissions can be Annoying</strong></p>
<p>Don’t ask me how because I won’t tell you, but on one of the hosts I was testing on that did not allow direct access I was able to get the Apache server running as dhapache to erroneously write a file into my users blog directory. This is a <strong>big security no-no</strong> and I now have my .htaccess file written into the blog directory where it should go, but instead of my php script’s user having write access to the file so I can modify it, its owned by dhapache! Because the file is owned by dhapache I shouldn’t even be allowed to know it exists, but there it is. So the next step was to try and take ownership of the .htaccess file so that I could modify it. I tried and tried but was unsuccessful, I couldn’t modify it so that was another dead end.  Actually it took me awhile to figure out how to remove the file from my directory. Being that it was owned by dhapache I couldn’t delete or modify it using my php process or even through ftp/ssh! Sysadmins regularly run find commands that search the servers for any files owned by <strong>dhapache</strong> that should not be there as this is a big red flag that someone has found a way to manipulate dhapache which could potentially lead to modifying dhapache-owned server config files, which sometimes is all it takes to hack your website and server..  Luckily I was able to delete it by basically running the hack again to overwrite the file.</p>]]></description>
			<content:encoded><![CDATA[<p>I wanted to address why the update to the AskApache Password Protection plugin didn&#8217;t happen pre-2009 as I had hoped.. Mostly due to my job but I thought I could at least fill you in.  Oh and this is going to get very boring very fast, unless you&#8217;re ready to rumble in the zone.</p>
<h2>File Permissions!</h2>
<p>The main issue with the password protection plugin working for some people and not others is due to <a href="http://www.askapache.com/security/chmod-stat.html"title="detailed file permission article" >file permission configurations</a>.  WordPress is simply a group of .php files saved on your server.  The actual program that is in fact running WordPress is the <a href="http://www.askapache.com/htaccess/php-cgi-redirect_status.html"title="SuEXEC and php.cgi" >PHP interpreter</a>, which is in turn controlled by the Apache Server.  Almost all computers are running at least 2 servers, the Web Server which serves and displays your files, and a FTP server.</p>
<p><a href="http://uploads.askapache.com/2009/03/apache-security-model-tall1.png" rel="nofollow" class="IFL" ><img src="http://uploads.askapache.com/2009/03/apache-security-model-tall1-250x123.png" alt="Apache Security Model - In Color" title="apache-security-model-wide" width="250" height="123" /></a>  Here&#8217;s a detailed look at the Apache Security Model, from <a href="http://www.apachesecurity.net/blog/2009/02/apache_security_model.html" rel="nofollow" >ApacheSecurity.net</a>, a blog maintained by <em>Ivan Ristic</em>, the author of <a href="http://www.modsecurity.org/" rel="nofollow" >ModSecurity</a>.<br class="C" /></p>
<p>The problem is happening because when you login to your FTP server with your username and password, the files that you upload are then  owned by that username and password, which is almost always an actual user account on the server system.  But the Apache Server is an executable file itself, and it is not owned by your FTP username, for security reasons.  Apache controls the PHP Interpreter, which parses and executes the WordPress and plugin files as a separate user.  ( <a href="http://httpd.apache.org/docs/trunk/suexec.html" rel="nofollow" >SuEXEC</a>, <a href="http://httpd.apache.org/docs/trunk/misc/security_tips.html" rel="nofollow" >Apache Security Tips</a> ) </p>
<p>So what happens is the <code>askapache-password-protect.php</code> file saved on your server and is owned by the user that created it (if you downloaded it to your computer then used ftp to transfer, your ftp user owns it..  if you used a php downloader script, then the php process owner owns it)   So when you click on the Run Tests button from the WordPress administration website what you are doing is sending a request via HTTP to your Apache Server process, which sees the requested file is .php so it then runs the php interpreter to execute the askapache-password-protect.php file, then that file uses programming to attempt and write/modify a file in your blog&#8217;s root directory.</p>
<h2>Process Owner vs. File Owner</h2>
<p>So who owns your blog&#8217;s root directory?  Your ftp user account/ you do..   but who owns the process that is trying to write/modify a file that is owned by your ftp user?  The PHP Process that is actually executing the file access/write requests.  This is the core way that 99% of all web sites get cracked into.. All these malicious robots and exploit bots do is attempt to write a file onto your server so that it can then be used to take over your site.  If they can save a file on your blog&#8217;s directory (uploads, insecure plugin code, not filtering user input, etc..) it inherits the permissions of the process that actually wrote the data bits onto the hard-drive.</p>
<p>So some server-admins/web hosts configure the php interpreter to not have write access anywhere except for a couple neccessary locations like /tmp.  They have auto-installation&#8217;s available through their online web panels, meaning instead of executing .php scripts in your user directory as the php process they force you to use, they can bypass all that because the installation scripts they use are all on their systems, not on your &#8220;locked-down&#8221; cluster.</p>
<p>This is the fundamental security battle that network server security is all based on..   Apache is owned by a powerful user because it owns the server process, so apache is often run as the user dhapache or nobody..  If a cracker is able to find a way to get a file saved on your server with the dhapache user as the owner then they&#8217;ve basically just gotten control of the whole thing.  When you upload a file to your server using the add attachment form in wordpress, the file first goes through the dhapache user which passes the file to the php process owner which has much less permissions.  Apache has been in open-source development for many many years now, its the safest most secure server in the world, windows servers are hackable, apache servers are hacked usually only when the sysadmin configures it wrong or accidentally.</p>
<p>Believe it or not, as confusing as my feeble explanation was, this is only like .1% of whats going on.. I&#8217;ve basically spent the last several months developing the new version specifically to be able to work no matter what configuration you have.  What I ended up doing was finding ways to bypass this security on a couple hosting providers that are setup in this way, but even though I got it to work in most instances it basically was hacking their systems, and if I published that code to automatically bypass web-hosts security setups I think I&#8217;d be in big trouble and they would just close those specific holes and the plugin would not work again.   So I decided instead of exploiting host-specifics hacks to get the plugin to work that I would focus on the method that WordPress sorta uses.  The code they have now (2.8 bleeding-edge) still isn&#8217;t where it needs to be, but this is some difficult stuff and they have a brilliant start, it&#8217;ll work.. just a question of when.</p>
<h2><code>wp-admin/includes/file.php</code></h2>
<p>Ok so this function <code>get_filesystem_method</code> is a brilliant bit of code that would&#8217;ve been beyond my current PHP skills to come up with.  It determines which if any of the following methods can be used to modify files on your server from within WordPress, which is exactly what the new version of the passpro plugin needs to use.   The first test simply creates a file from within php using wp_tempnam, a function that attempts to locate and write to a temporary location on your server that has the best chance of having write access.  If it is successfully created (this code assumes that it will be, something they need to fix) then the fileowner (uses stat internally) of the temp file just created is compared to the owner of the php script&#8230;  Normally this works and then the plugin woks too, but on some hosts the script is running as a separate user than that of the file which means you can&#8217;t directly access the local file system.  That is what is occurring for most of you who experience permission problems while testing the plugin.  There are thousands of caveats for each little part depending on your php version, php setup, server setup, server version, which Server API you are using, the type of SAPI being used, and on and on..</p>
<pre>function get_filesystem_method($args = array()) {
  $method = false;
  if( function_exists(&#039;getmyuid&#039;) &amp;&amp; function_exists(&#039;fileowner&#039;) ){
    $temp_file = wp_tempnam();
    if ( getmyuid() == fileowner($temp_file) ) $method = &#039;direct&#039;;
    unlink($temp_file);
  }
  if ( ! $method &amp;&amp; isset($args[&#039;connection_type&#039;]) &amp;&amp; &#039;ssh&#039; == $args[&#039;connection_type&#039;] &amp;&amp; extension_loaded(&#039;ssh2&#039;) )
          $method = &#039;ssh2&#039;;
  if ( ! $method &amp;&amp; extension_loaded(&#039;ftp&#039;) )
          $method = &#039;ftpext&#039;;
  if ( ! $method &amp;&amp; ( extension_loaded(&#039;sockets&#039;) || function_exists(&#039;fsockopen&#039;) ) )
          $method = &#039;ftpsockets&#039;; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
  return apply_filters(&#039;filesystem_method&#039;, $method);
}</pre>
<h2>Enumerating Permissions can be Annoying</h2>
<p>This was part of some tests I did to see what kind of access I had with the very helpful posix functions which are very accurate as well since they were designed for a system with file permissions, ie. not Win.  Don&#8217;t ask me how because I won&#8217;t tell you, but on one of the hosts I was testing on that did not allow direct access I was able to get the Apache server running as dhapache to erroneously write a file into my users blog directory.  This is a big security no-no and I now have my .htaccess file written into the blog directory where it should go, but instead of my php script&#8217;s user having write access to the file so I can modify it, its owned by dhapache!  Because the file is owned by dhapache I shouldn&#8217;t even be allowed to know it exists, but there it is.  So the next step was to try and take ownership of the .htaccess file so that I could modify it.  I tried and tried but was unsuccessful, I couldn&#8217;t modify it so that was another dead end.  Actually it took me awhile to figure out how to remove the file from my directory.  Being that it was owned by dhapache I couldn&#8217;t delete or modify it using my php process or even through ftp/ssh!  Sysadmins regularly run find commands that search the servers for any files owned by dhapache that should not be there as this is a big red flag that someone has found a way to manipulate dhapache which could potentially lead to modifying dhapche-owned server config files.. Luckily I was able to delete it by basically running the hack again to overwrite the file.</p>
<pre>  if ((posix_setgid(getmygid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETGID of {$file}  to &quot; . getmygid(), 3);
  elseif ((posix_setgid(filegroup(__file__))) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETUID of {$file} to &quot; . filegroup(__file__), 3);
  if ((posix_setegid(getmygid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETEGID of {$file} to &quot; . getmygid(), 3);
  elseif ((posix_setegid(filegroup(__file__))) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETEGID of {$file} to &quot; . filegroup(__file__), 3);
  if ((posix_setuid(getmyuid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETUID of {$file}  to &quot; . getmyuid(), 3);
  elseif ((posix_setuid(get_current_user())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETUID of {$file} to &quot; . get_current_user(), 3);
  if ((posix_seteuid(getmyuid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETEUID of {$file} to &quot; . getmyuid(), 3);
  elseif ((posix_seteuid(get_current_user())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing SETEUID of {$file} to &quot; . get_current_user(), 3);
  if ((chmod($file, FS_CHMOD_DIR) || chmod($file, 0776) || chmod($file, 0766) || chmod($file,
    FS_CHMOD_FILE)) !== false) $this-&gt;to_log(&#039;&#039;, 1, &quot;Success Changing Mode of {$file}&quot;, 3);
  if ((chown($file, getmyuid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Ownership of {$file} to &quot; . getmyuid(), 3);
  elseif ((chown($file, get_current_user())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Ownership of {$file} to &quot; . get_current_user(), 3);
  if ((chgrp($file, getmygid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Group of {$file} to &quot; . getmygid(), 3);
  elseif ((chgrp($file, filegroup(__file__))) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Group of {$file} to &quot; . filegroup(__file__), 3);
  if ((chmod($file, FS_CHMOD_DIR) || chmod($file, 0776) || chmod($file, 0766) || chmod($file,
    FS_CHMOD_FILE)) !== false) $this-&gt;to_log(&#039;&#039;, 1, &quot;Success Changing Mode of {$file}&quot;, 3);
  if ((chown($file, getmyuid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Ownership of {$file} to &quot; . getmyuid(), 3);
  elseif ((chown($file, get_current_user())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Ownership of {$file} to &quot; . get_current_user(), 3);
  if ((chgrp($file, getmygid())) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Group of {$file} to &quot; . getmygid(), 3);
  elseif ((chgrp($file, filegroup(__file__))) !== false) $this-&gt;to_log(&#039;&#039;, 1,
      &quot;Success Changing Group of {$file} to &quot; . filegroup(__file__), 3);
  return (!$this-&gt;_fclose($fh)) ? $this-&gt;to_log(__function__ . &#039;:&#039; . __line__ .
    &quot; Error closing {$mode} handle for {$file}&quot;, 0) : $total;</pre>
<p>If php process isn&#8217;t allowed to write to your web directory but you have an ftp account that is, then we request your ftp username/password in wordpress and if the php process running the <code>askapache-password-protect.php</code> plugin script is allowed access to <a href="http://www.askapache.com/php/fsockopen-socket.html">raw networking sockets using fsockopen</a> then we can basically access and write to your blog&#8217;s <code>.htaccess</code> file by using php to mimick an ftp client session. There are also other protocols and options available using php if ftp/fsockopen isn&#8217;t allowed, but you run out of alternatives quick.  Using the curl extension is one option.</p>
<p>So I wrote my own ftp library for a fsockopen class I had already developed for specific test requirements in unreleased versions, so the release of the new askapache password protect plugin will work for 75% or so of the people who have trouble now.. not to mention the insane logging and debugging I&#8217;ve added while looking for the reasons some web-hosts still don&#8217;t work.  Some use custom php security modules, wrappers, and custom virtual servers that are akin to a vmware server.  So for maybe 10% of those running apache who have had problems they would still have them. I&#8217;m still playing with some ssh capability from within the plugin similar to the ftp technique..  I really hope WordPress just adds this functionality by updating their current filesystem classes..</p>
<h2>Fsockopen Payload Class</h2>
<p>Here&#8217;s what I had several versions ago.. Just sticking it up here in case anyone is curious, one cool thing this version starts to incorporate is being able to send direct data payloads across the socket so it can be used like <a href="http://metasploit.com/" rel="nofollow"  title="Metasploit provides useful information to people who perform penetration testing, IDS signature development, and exploit research.">the metasploit framework</a> to send payloads of exploits, but of course we&#8217;re using it to mimick other protocols like ftp, which can be setup by feeding hex into the socket direct from a real ftp client, and piping the output. Keep in mind that this is my first time using php classes, so the learning curve has been incredible&#8230;</p>
<pre>&lt;?php
error_log(&quot;RUNNING &quot; . basename(__file__) . &quot;\n&quot;);
if (!in_array(&#039;AskApache_Net&#039;, get_declared_classes()) &amp;&amp; !class_exists(&#039;AskApache_Net&#039;)):
 class AskApache_Net extends AskApachePassPro
 {
  var $_fp = null;
  var $_socket = array(&#039;protocol&#039; =&gt; &#039;1.0&#039;, &#039;method&#039; =&gt; &#039;GET&#039;, &#039;referer&#039; =&gt;
   &#039;http://www.askapache.com/&#039;, &#039;port&#039; =&gt; &#039;80&#039;, &#039;ua&#039; =&gt;
   &#039;Mozilla/5.0 (compatible; AskApache_Net/1.6; http://www.askapache.com/)&#039;, &#039;scheme&#039; =&gt;
   &#039;http&#039;, &#039;transport&#039; =&gt; &#039;&#039;, &#039;host&#039; =&gt; &#039;&#039;, &#039;user&#039; =&gt; &#039;&#039;, &#039;pass&#039; =&gt; &#039;&#039;, &#039;path&#039; =&gt; &#039;/&#039;,
   &#039;query&#039; =&gt; &#039;&#039;, &#039;fragment&#039; =&gt; &#039;&#039;);
  var $authtype = &#039;Basic&#039;;
  var $timeout = 15;
  var $_dh = &#039;&#039;;
  var $_digest = array(&#039;realm&#039; =&gt; &#039;&#039;, &#039;nonce&#039; =&gt; &#039;&#039;, &#039;uri&#039; =&gt; &#039;&#039;, &#039;algorithm&#039; =&gt; &#039;MD5&#039;,
   &#039;qop&#039; =&gt; &#039;auth&#039;, &#039;opaque&#039; =&gt; &#039;&#039;, &#039;domain&#039; =&gt; &#039;&#039;, &#039;nc&#039; =&gt; &#039;00000001&#039;, &#039;cnonce&#039; =&gt;
   &#039;82d057852a9dc497&#039;, &#039;A1&#039; =&gt; &#039;&#039;, &#039;A2&#039; =&gt; &#039;&#039;, &#039;response&#039; =&gt; &#039;&#039;);
  var $_ACLF = &quot;\r\n&quot;;
  var $_request_body = &#039;&#039;;
  var $_request_headers = array();
  var $_response_headers = array();
  var $my_headers;
  var $_response_header = &#039;&#039;;
  var $_response_protocol = &#039;&#039;;
  var $_response_version = &#039;&#039;;
  var $_response_code = &#039;&#039;;
  var $_response_message = &#039;&#039;;
  var $_response_body = &#039;&#039;;
  var $_errs = array(3 =&gt; &#039;Socket creation failed&#039;, 4 =&gt; &#039;DNS lookup failure&#039;, 5 =&gt;
   &#039;Connection refused or timed out&#039;, 111 =&gt; &#039;Connection refused&#039;, 113 =&gt;
   &#039;No route to host&#039;, 110 =&gt; &#039;Connection timed out&#039;, 104 =&gt; &#039;Connection reset by client&#039;);

  /**
   * AskApache_Net::AskApache_Net()
   */
  function AskApache_Net()
  {
   return $this-&gt;__construct();
  }

  /**
   * AskApache_Net::__destruct()
   */
  function __destruct()
  {
   $this-&gt;_timer(&#039;class&#039;);
   return true;
  }

  /**
   * AskApache_Net::__construct()
   */
  function __construct()
  {
   $this-&gt;_timer(&#039;class&#039;);
   $this-&gt;_ACLF = chr(13) . chr(10);
   @set_time_limit(60);
   return true;
  }

  /**
   * AskApache_Net::hsockit()
   */
  function hsockit($URI)
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   $this-&gt;_socket[&#039;method&#039;] = &#039;HEAD&#039;;
   return $this-&gt;sockit($URI);
  }

  /**
   * AskApache_Net::sockit()
   */
  function sockit($URI = &#039;&#039;)
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if (!$this-&gt;_build_sock($URI)) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__,
     &quot;Failed!&quot;, 0);
   if (!$this-&gt;_connect()) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__, &quot;Failed!&quot;, 0);
   $this-&gt;_build_request();
   if (!$this-&gt;_build_request()) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__,
     &quot;Failed!&quot;, 0);
   if (!$this-&gt;_tx()) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__, &quot;tx Failed!&quot;, 0);
   if (!$this-&gt;_rx()) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__, &quot;rx Failed!&quot;, 0);
   if (!$this-&gt;_disconnect()) return $this-&gt;msg(__function__ . &#039;:&#039; . __line__,
     &quot;disconnect Failed!&quot;, 0);
   if ((bool)$this-&gt;net_debug === true) {
    foreach (array(&#039;out_payload&#039;, &#039;_request_body&#039;, &#039;_response_header&#039;, &#039;_response_body&#039;) as
     $nam) {
     if (is_array($this-&gt;$nam)) {
      if (sizeof($this-&gt;$nam) &gt; 1) {
       echo &quot;\n\n{$nam}\n&quot;;
       print_r($this-&gt;$nam);
      }
     } else {
&nbsp;
      if (!empty($this-&gt;$nam)) {
       echo &quot;\n\n{$nam}\n&quot;;
       echo $this-&gt;$nam;
      }
     }
    }
    $this-&gt;tcp_trace(1);
   }
   return (int)$this-&gt;_response_code;
  }

  /**
   * AskApache_Net::_build_sock()
   */
  function _build_sock($url)
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   $socket_info = &amp;$this-&gt;_socket;
   if (!$u_bits = parse_url($url)) return false;
   if (empty($u_bits[&#039;method&#039;])) $u_bits[&#039;method&#039;] = &#039;GET&#039;;
   if (empty($u_bits[&#039;protocol&#039;])) $u_bits[&#039;protocol&#039;] = &#039;1.0&#039;;
   if (empty($u_bits[&#039;host&#039;])) $u_bits[&#039;host&#039;] = $_SERVER[&#039;HTTP_HOST&#039;];
   if (empty($u_bits[&#039;scheme&#039;])) $u_bits[&#039;scheme&#039;] = &#039;http&#039;;
   if (empty($u_bits[&#039;port&#039;])) $u_bits[&#039;port&#039;] = $_SERVER[&#039;SERVER_PORT&#039;];
   $u_bits[&#039;path&#039;] = (empty($u_bits[&#039;path&#039;]) ? &#039;/&#039; : $u_bits[&#039;path&#039;]) . (!empty($u_bits[&#039;query&#039;]) ?
    &#039;?&#039; . $u_bits[&#039;query&#039;] : &#039;&#039;);
   if (empty($u_bits[&#039;ua&#039;])) $u_bits[&#039;ua&#039;] =
     &#039;Mozilla/5.0 (compatible; AskApache_Net/1.0; http://www.askapache.com)&#039;;
   if (empty($u_bits[&#039;referer&#039;])) $u_bits[&#039;referer&#039;] = &#039;http://www.askapache.com&#039;;
   if (empty($u_bits[&#039;fragment&#039;])) unset($u_bits[&#039;fragment&#039;]);
   if (empty($u_bits[&#039;user&#039;])) unset($u_bits[&#039;user&#039;]);
   if (empty($u_bits[&#039;pass&#039;])) unset($u_bits[&#039;pass&#039;]);
   if ($u_bits[&#039;scheme&#039;] == &#039;https&#039; || $this-&gt;_socket[&#039;scheme&#039;] == &#039;https&#039;) $u_bits[&#039;transport&#039;] =
     &#039;ssl://&#039;;
   if ($u_bits[&#039;scheme&#039;] == &#039;https&#039; || $this-&gt;_socket[&#039;scheme&#039;] == &#039;https&#039;) $u_bits[&#039;port&#039;] =
     &#039;443&#039;;
   $socket_info = $this-&gt;_parse_args($u_bits, $socket_info);
   extract($socket_info, EXTR_SKIP);
   return true;
  }

  /**
   * AskApache_Net::_build_auth_header()
   */
  function _build_auth_header()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if ($this-&gt;authtype == &#039;Basic&#039;) $this-&gt;_request_headers[] = &#039;Authorization: Basic &#039; .
     base64_encode($this-&gt;_socket[&#039;user&#039;] . &quot;:&quot; . $this-&gt;_socket[&#039;pass&#039;]);
   elseif ($this-&gt;authtype == &#039;Digest&#039;) {
    $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
    $this-&gt;_socket[&#039;protocol&#039;] = &#039;1.1&#039;;
    $hdr = $mtx = array();
    preg_match_all(&#039;/(\w+)=(?:&quot;([^&quot;]+)&quot;|([^\s,]+))/&#039;, $this-&gt;_dh, $mtx, PREG_SET_ORDER);
    foreach ($mtx as $m) $hdr[$m[1]] = $m[2] ? $m[2] : $m[3];
    foreach ($hdr as $key =&gt; $val)
     if (array_key_exists($key, $this-&gt;_digest) &amp;&amp; !empty($val)) $this-&gt;_digest[$key] = $val;
    $this-&gt;_digest[&#039;uri&#039;] = $this-&gt;_socket[&#039;path&#039;];
    $this-&gt;_digest[&#039;A1&#039;] = md5($this-&gt;_socket[&#039;user&#039;] . &#039;:&#039; . $this-&gt;_digest[&#039;realm&#039;] .
     &#039;:&#039; . $this-&gt;_socket[&#039;pass&#039;]);
    $this-&gt;_digest[&#039;A2&#039;] = md5($this-&gt;_socket[&#039;method&#039;] . &#039;:&#039; . $this-&gt;_socket[&#039;path&#039;]);
    $this-&gt;_digest[&#039;response&#039;] = md5($this-&gt;_digest[&#039;A1&#039;] . &#039;:&#039; . $this-&gt;_digest[&#039;nonce&#039;] .
     &#039;:&#039; . $this-&gt;_digest[&#039;nc&#039;] . &#039;:&#039; . $this-&gt;_digest[&#039;cnonce&#039;] . &#039;:&#039; . $this-&gt;_digest[&#039;qop&#039;] .
     &#039;:&#039; . $this-&gt;_digest[&#039;A2&#039;]);
    $this-&gt;_request_headers[] = sprintf(&#039;Authorization: Digest username=&quot;%1$s&quot;, realm=&quot;%2$s&quot;, nonce=&quot;%3$s&quot;,&#039;.
     &#039;uri=&quot;%4$s&quot;, algorithm=%5$s, response=&quot;%6$s&quot;, qop=&quot;%7$s&quot;, nc=&quot;%8$s&quot;%9$s%10$s&#039;,
     $this-&gt;_socket[&#039;user&#039;], $this-&gt;_digest[&#039;realm&#039;], $this-&gt;_digest[&#039;nonce&#039;], $this-&gt;
     _digest[&#039;uri&#039;], $this-&gt;_digest[&#039;algorithm&#039;], $this-&gt;_digest[&#039;response&#039;], $this-&gt;
     _digest[&#039;qop&#039;], $this-&gt;_digest[&#039;nc&#039;], !empty($this-&gt;_digest[&#039;cnonce&#039;]) ? &#039;, cnonce=&quot;&#039; .
     $this-&gt;_digest[&#039;cnonce&#039;] . &#039;&quot;&#039; : &#039;&#039;, !empty($this-&gt;_digest[&#039;opaque&#039;]) ? &#039;, opaque=&quot;&#039; .
     $this-&gt;_digest[&#039;opaque&#039;] . &#039;&quot;&#039; : &#039;&#039;);
   }
   return true;
  }

  /**
   * AskApache_Net::_build_request()
   */
  function _build_request()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   $this-&gt;_request_headers[] = $this-&gt;_socket[&#039;method&#039;] . &quot; &quot; . $this-&gt;_socket[&#039;path&#039;] .
    &quot; HTTP/&quot; . $this-&gt;_socket[&#039;protocol&#039;];
   if (is_array($this-&gt;my_headers) &amp;&amp; sizeof($this-&gt;my_headers) &gt; 0) $this-&gt;
     _request_headers = array_merge($this-&gt;_request_headers, $this-&gt;my_headers);
   else {
    $this-&gt;_request_headers[] = &quot;Host: &quot; . $this-&gt;_socket[&#039;host&#039;];
    $this-&gt;_request_headers[] = &quot;User-Agent: &quot; . $this-&gt;_socket[&#039;ua&#039;];
    $this-&gt;_request_headers[] = &#039;Accept: application/xhtml+xml,text/html;q=0.9,*/*;q=0.5&#039;;
    $this-&gt;_request_headers[] = &#039;Accept-Language: en-us,en;q=0.5&#039;;
    $this-&gt;_request_headers[] = &#039;Accept-Encoding: none&#039;;
    $this-&gt;_request_headers[] = &#039;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&#039;;
    $this-&gt;_request_headers[] = &#039;Referer: &#039; . $this-&gt;_socket[&#039;referer&#039;];
   }
   if (!empty($this-&gt;_socket[&#039;user&#039;]) &amp;&amp; !empty($this-&gt;_socket[&#039;pass&#039;])) $this-&gt;
     _build_auth_header();
   if ($this-&gt;out_payload !== false) $this-&gt;_request_body = $this-&gt;out_payload;
   else  $this-&gt;_request_body = join($this-&gt;_ACLF, $this-&gt;_request_headers) . $this-&gt;
     _ACLF . $this-&gt;_ACLF;
   return true;
  }

  /**
   * AskApache_Net::_tx()
   */
  function _tx()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   return (bool)(is_resource($this-&gt;_fp) &amp;&amp; $this-&gt;_netwrite($this-&gt;_fp, $this-&gt;
    _request_body));
  }

  /**
   * AskApache_Net::_rx()
   */
  function _rx()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if (!is_resource($this-&gt;_fp)) return false;
   $this-&gt;_response = $this-&gt;_netread($this-&gt;_fp, 500000);
   $parts = explode($this-&gt;_ACLF . $this-&gt;_ACLF, ltrim($this-&gt;_response), 2);
   $this-&gt;_response_header = trim($parts[0]);
   $this-&gt;_response_body = trim($parts[1]);
   if (preg_match(&#039;#([^/]*)/([\d\.]+) ([\d]*?) (.*)#&#039;, $this-&gt;_response_header, $htx)) {
    $this-&gt;_response_protocol = trim($htx[1]);
    $this-&gt;_response_version = trim($htx[2]);
    $this-&gt;_response_code = trim($htx[3]);
    $this-&gt;_response_message = trim($htx[4]);
   }
   if (preg_match_all(&#039;#([^:]+)\:?(.*)#&#039;, str_replace($htx, &#039;&#039;, $this-&gt;_response_header),
    $mtx, PREG_SET_ORDER)) {
    foreach ($mtx as $m) {
     $this-&gt;_headers[strtolower(trim($m[1]))] = trim($m[2]);
     if (preg_match(&#039;/(WWW|Proxy)-Authenticate:.*Digest/i&#039;, trim($m[1]))) $this-&gt;_dh =
       trim($m[1]);
    }
   }
   return true;
  }

  /**
   * AskApache_Net::tcp_trace()
   */
  function tcp_trace($p = false)
  {
   $this-&gt;_timer(__function__ );
   $ret = join(&quot;\n&quot;, array_merge((array )$this-&gt;_request_headers, array(&#039;&#039;), (array )$this-&gt;
    _response_headers));
   if ($p !== false) {
    echo $ret;
    $ret = true;
   }
   $this-&gt;_timer(__function__ );
   return $ret;
  }

  /**
   * AskApache_Net::_get_ip()
   */
  function _get_ip($host)
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
&nbsp;
   if (!preg_match(&#039;/^[\t ]*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[\t ]*$/&#039;, $host)) $hostip =
     gethostbyname($host);
   $ip = ($hostip == $host) ? $host : long2ip(ip2long($hostip));
   return $ip;
  }

  /**
   * AskApache_Net::_connect()
   */
  function _connect()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if (false === ($this-&gt;_fp = fsockopen($this-&gt;_get_ip($this-&gt;_socket[&#039;host&#039;]), $this-&gt;
    _socket[&#039;port&#039;], $errno, $errstr, $this-&gt;timeout)) || !is_resource($this-&gt;_fp)) {
    $err = (array_key_exists($errno, $this-&gt;_errs)) ? $this-&gt;_errs[$errno] :
     &#039;Connection failed&#039;;
    return $this-&gt;msg(__function__ . &#039;:&#039; . __line__ . &quot; Fsockopen failed! [{$errno}] {$err} ({$errstr})&quot;,
     0);
   }
   if (function_exists(&quot;socket_set_timeout&quot;)) socket_set_timeout($this-&gt;_fp, $this-&gt;
     timeout);
   elseif (function_exists(&quot;stream_set_timeout&quot;)) stream_set_timeout($this-&gt;_fp, $this-&gt;
     timeout);
   usleep(10000);
   return true;
  }

  /**
   * AskApache_Net::_disconnect()
   */
  function _disconnect()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if (is_resource($this-&gt;_fp)) return $this-&gt;_fclose($this-&gt;_fp);
   else  $this-&gt;_fp = null;
   return true;
  }

  /**
   * AskApache_Net::get_response_headers()
   */
  function get_response_headers($header = false)
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   if ($header !== false &amp;&amp; array_key_exists($header, $this-&gt;_response_headers)) return $this-&gt;
     _response_headers[$header];
   return $this-&gt;_response_headers;
  }

  /**
   * AskApache_Net::get_response_body()
   */
  function get_response_body()
  {
   $this-&gt;msg(__function__ . &#039;:&#039; . __line__, 3);
   return $this-&gt;_response_body;
  }

  /**
   * AskApache_Net::_netread()
   */
  function _netread(&amp;$fh, $ts = 50000000, $bs = 124)
  {
   $this-&gt;_timer(__function__ );
   for ($d = $b = &#039;&#039;, $rt = $at = $r = 0; ($fh !== false &amp;&amp; !feof($fh) &amp;&amp; $b !== false &amp;&amp;
    $at &lt; 50000000 &amp;&amp; $rt &lt; $ts); $r = $ts - $rt, $bs = (($bs &gt; $r) ? $r : $bs), $this-&gt;
    _timer(&quot;R: {$rt}&quot;), $b = fread($fh, $bs), $br = strlen($b), $d .= $b, $this-&gt;_timer(&quot;R: {$rt}&quot;),
    $rt += $br, $at++, $this-&gt;msg(&quot;[RT: {$rt}]\t[BR: {$br}&quot; . (($ts != 50000000) ? &quot;]\t\t [{$r} / {$ts}]&quot; :
    &quot; : {$bs}]\t[{$at}]&quot;))) ;
   $this-&gt;_timer(__function__ );
   return ((strlen($d) != 0)) ? $d : false;
  }

  /**
   * AskApache_Net::_netwrite()
   */
  function _netwrite(&amp;$fh, $d = &#039;&#039;, $bs = 512)
  {
   $this-&gt;_timer(__function__ );
&nbsp;
   for ($bw = $wt = $at = 0, $dat = &#039;&#039;, $ts = strlen($d); ($fh !== false &amp;&amp; $bw !== false &amp;&amp;
    $at &lt; 50000000 &amp;&amp; $wt &lt; $ts); $r = $ts - $wt, $bs = (($bs &gt; $r) ? $r : $bs), $dat =
    substr($d, $wt, $bs), $bw = fwrite($fh, $dat), $wt += $bw, $this-&gt;msg(&quot;[WT: {$wt}]\t[BW: {$bw}]\t\t[I: {$r} / {$ts}:{$bs}] - {$at}&quot;),
    $at++) ;
   $this-&gt;msg(&quot;[WT: {$wt}]\t[BW: {$bw}]\t\t[I: {$r} / {$ts}:{$bs}] - {$at}&quot;);
   $this-&gt;_timer(__function__ );
   return ($wt == $ts) ? true : false;
  }
 }
endif;
?&gt;</pre>
<p>So I decided to finally give in to what I&#8217;ve been avoiding all along and added a php-software-based method that will work on everycomputer, windows, blackberrys, etc.. That took me about 15minutes as its just a few lines of code.. The problem I have with it is that php is what is actually controlling the sending, receiving, and verifying of the authentication headers instead of using the builtin super-secure apache method.</p>
<p>Here&#8217;s how you would block someone using the apache/askapache way:</p>
<pre>[Exploit Request] =&gt; ([BLOCKED]-AskApache)</pre>
<p>This prevents the exploit from even reaching PHP, saving your computer a lot of CPU/memory and bandwdith, and obviously can&#8217;t exploit wordpress if php isn&#8217;t even loading.</p>
<p>Here&#8217;s how the php-software-based method blocks the same request:</p>
<pre>[Exploit Request] =&gt; (AskApache) =&gt; (PHP) =&gt; (WordPress) =&gt; ([BLOCKED]-askapache-password-protect.php)</pre>
<p>So the last bit of programming and research I&#8217;m doing at the moment is how to cause the askapache-password-protect plugin to execute as soon as possible, ideally it would execute before WordPress starts..   And I am still crazy swamped at work, this was the longest non-posting period of the blog to date!</p>
<p><a href="http://www.askapache.com/htaccess/password-protection-plugin-status.html"></a><a href="http://www.askapache.com/htaccess/password-protection-plugin-status.html">Password Protection Plugin Status</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/password-protection-plugin-status.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</title>
		<link>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html</link>
		<comments>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html#comments</comments>
		<pubDate>Sat, 22 Nov 2008 14:18:12 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[.htaccess plugin]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Anti-Spam]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[htaccess rewrite]]></category>
		<category><![CDATA[htaccess tricks]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[Mod_Setenvif]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Request Method]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1053</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png" alt=".htaccess security plugin 2" title=".htaccess security plugin 2" width="269" height="436" /></a><br /><br />Well what can I say, <strong>other than this is sooo DOPE</strong>!  Here is a list of the modules this plugin (version 4.7 unreleased) will automatically detect.  I compiled the list myself using every module included with any default Apache installation for ALL the versions listed below, 1.3 to 2.2+<br /><br />Want to know something else I'm including in this plugin?  For each and every module that is detected, this plugin can then detect ALL of the modules .htaccess Directives!  For instance, <code>RewriteRule, AccessFileName, AddHandler, etc..</code> are each a directive belonging to a module that is allowed to be used from within .htaccess files.<br /><br /><strong>Talk about sick.. these tricks have the diamond disease!</strong><br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png" rel="nofollow" class="IFL" ><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png" alt=".htaccess security plugin 2" title=".htaccess security plugin 2" /></a></p>
<p>Well what can I say, <strong>other than this is sooo DOPE</strong>!  Here is a <a href="#htaccess-module-list" rel="nofollow" >list of the modules</a> this plugin (version 4.7 unreleased) will automatically detect.  I compiled the list myself using every module included with any default Apache installation for ALL the versions listed below, 1.3 to 2.2+</p>
<p>Want to know something else I&#8217;m including in this plugin?  For each and every module that is detected, this plugin can then detect ALL of the modules .htaccess Directives!  For instance, <code>RewriteRule, AccessFileName, AddHandler, etc..</code> are each a directive belonging to a module that is allowed to be used from within .htaccess files.</p>
<p><strong>Talk about sick.. these tricks have the diamond disease!</strong><br class="C" /></p>
<h2>Screenshot Unreleased 4.7</h2>
<p>I&#8217;ve been making a lot of progress as these screenshots illustrate, including the ability to detect 100% accurately the modules that are enabled on your server.  Big deal!  you might say&#8230; &#8220;How does knowing the modules help?&#8221;</p>
<p>Well it just so happens that in addition to detecting which modules are loaded on your server, this plugin will also detect which Directives are enabled for each module that are allowed to be used from within your .htaccess file!  Future release will provide the ability to explore the different .htaccess directives allowed by your server, so you can do all sorts of cool Apache .htaccess tricks to secure your blog and make it run better.</p>
<p><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-1.png" rel="nofollow" ><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-1.png" alt=".htaccess security plugin 1" title=".htaccess security plugin 1" /></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-3.png" rel="nofollow" ><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-3.png" alt=".htaccess security plugin 3" title=".htaccess security plugin 3" /></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-4.png" rel="nofollow" ><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-4.png" alt=".htaccess security plugin 4" title=".htaccess security plugin 4" /></a></p>
<h2><a id="htaccess-module-list">Apache Module Detection</a></h2>
<p>Future releases of this plugin will also let you search for non-default modules, wild, beta, and others.</p>
<ul>
<li>mod_access</li>
<li>mod_actions</li>
<li>mod_alias</li>
<li>mod_asis</li>
<li>mod_auth</li>
<li>mod_auth_anon</li>
<li>mod_auth_basic</li>
<li>mod_auth_dbm</li>
<li>mod_auth_digest</li>
<li>mod_auth_ldap</li>
<li>mod_authn_alias</li>
<li>mod_authn_anon</li>
<li>mod_authn_dbd</li>
<li>mod_authn_dbm</li>
<li>mod_authn_default</li>
<li>mod_authn_file</li>
<li>mod_authnz_ldap</li>
<li>mod_authz_dbm</li>
<li>mod_authz_default</li>
<li>mod_authz_groupfile</li>
<li>mod_authz_host</li>
<li>mod_authz_owner</li>
<li>mod_authz_user</li>
<li>mod_autoindex</li>
<li>mod_bucketeer</li>
<li>mod_cache</li>
<li>mod_case_filter</li>
<li>mod_case_filter_in</li>
<li>mod_cern_meta</li>
<li>mod_cgi</li>
<li>mod_cgid</li>
<li>mod_charset_lite</li>
<li>mod_dav</li>
<li>mod_dav_fs</li>
<li>mod_dav_lock</li>
<li>mod_dbd</li>
<li>mod_deflate</li>
<li>mod_dir</li>
<li>mod_disk_cache</li>
<li>mod_dumpio</li>
<li>mod_echo</li>
<li>mod_env</li>
<li>mod_example</li>
<li>mod_expires</li>
<li>mod_ext_filter</li>
<li>mod_file_cache</li>
<li>mod_filter</li>
<li>mod_headers</li>
<li>mod_ident</li>
<li>mod_imagemap</li>
<li>mod_imap</li>
<li>mod_include</li>
<li>mod_info</li>
<li>mod_isapi</li>
<li>mod_log_config</li>
<li>mod_log_forensic</li>
<li>mod_logio</li>
<li>mod_mem_cache</li>
<li>mod_mime</li>
<li>mod_mime_magic</li>
<li>mod_mycore</li>
<li>mod_negotiation</li>
<li>mod_netware</li>
<li>mod_nw_ssl</li>
<li>mod_optional_fn_export</li>
<li>mod_optional_fn_import</li>
<li>mod_optional_hook_export</li>
<li>mod_optional_hook_import</li>
<li>mod_proxy</li>
<li>mod_proxy_ajp</li>
<li>mod_proxy_balancer</li>
<li>mod_proxy_connect</li>
<li>mod_proxy_ftp</li>
<li>mod_proxy_http</li>
<li>mod_rewrite</li>
<li>mod_security</li>
<li>mod_setenvif</li>
<li>mod_so</li>
<li>mod_speling</li>
<li>mod_ssl</li>
<li>mod_status</li>
<li>mod_substitute</li>
<li>mod_suexec</li>
<li>mod_test</li>
<li>mod_unique_id</li>
<li>mod_userdir</li>
<li>mod_usertrack</li>
<li>mod_version</li>
<li>mod_vhost_alias</li>
<li>mod_win32</li>
</ul>
<p><a href="http://www.askapache.com/wordpress/htaccess-password-protect.html"rel="lb" class="IFL hs hs35" href='http://uploads.askapache.com/2008/07/http-security-askapache.png' title="http-security-askapache"></a>The original plugin page and description <a >can be found here</a>.<br class="C" /></p>
<h2>UPDATE: 11/22/08</h2>
<p><a rel="lb" class="IFL hs hs35" href='http://uploads.askapache.com/2008/07/http-security-askapache.png' title="http-security-askapache"></a><strong>To make a long story short,</strong> I downloaded each major release of the apache httpd source code from version 1.3.0 to version 2.2.10, then I configured and compiled each for a custom HTTPD installation built from source.  This allowed me to find every directive allowed in .htaccess files for each particular version.  <strong style="font-weight:bold;">YES!</strong><br class="C" /></p>
<blockquote cite="http://wordpress.org/support/topic/214390"><p><cite><a href="http://wordpress.org/support/rss/topic/214390" rel="nofollow" >http://wordpress.org/support/rss/topic/214390</a></cite><br />
I&#8217;ve been working on a completely improved version on/off for about a month with the specific goal of finally ending all the little errors that can crop up when dealing with .htaccess.</p>
<p>To that effect I am succeeding marvelously, first I&#8217;ve converted the plugin to a class (4+5 compat), I&#8217;ve replaced my error_handling with WordPress&#8217;s WP_Error class, and the coolest change is the new tests I&#8217;ve added.</p>
<p>To make a long story short, I downloaded each major release of the apache httpd source code starting at version 1.3.0 and finishing with version 2.2.10, I then compiled each version and built a HTTPD from source for all the apache versions.  </p>
<p><em><code>1.3.0</code>, <code>1.3.1</code>, <code>1.3.11</code>, <code>1.3.12</code>, <code>1.3.14</code>, <code>1.3.17</code>, <code>1.3.19</code>, <code>1.3.2</code>, <code>1.3.20</code>, <code>1.3.22</code>, <code>1.3.23</code>, <code>1.3.24</code>, <code>1.3.27</code>, <code>1.3.28</code>, <code>1.3.29</code>, <code>1.3.3</code>, <code>1.3.31</code>, <code>1.3.32</code>, <code>1.3.33</code>, <code>1.3.34</code>, <code>1.3.35</code>, <code>1.3.36</code>, <code>1.3.37</code>, <code>1.3.39</code>, <code>1.3.4</code>, <code>1.3.41</code>, <code>1.3.6</code>, <code>1.3.9</code>, <code>2.0.35</code>, <code>2.0.36</code>, <code>2.0.39</code>, <code>2.0.40</code>, <code>2.0.42</code>, <code>2.0.43</code>, <code>2.0.44</code>, <code>2.0.45</code>, <code>2.0.46</code>, <code>2.0.47</code>, <code>2.0.48</code>, <code>2.0.49</code>, <code>2.0.50</code>, <code>2.0.51</code>, <code>2.0.52</code>, <code>2.0.53</code>, <code>2.0.54</code>, <code>2.0.55</code>, <code>2.0.58</code>, <code>2.0.59</code>, <code>2.0.61</code>, <code>2.0.63</code>, <code>2.1.3-beta</code>, <code>2.1.6-alpha</code>, <code>2.1.7-beta</code>, <code>2.1.8-beta</code>, <code>2.1.9-beta</code>, <code>2.2.0</code>, <code>2.2.10</code>, <code>2.2.2</code>, <code>2.2.3</code>, <code>2.2.4</code>, <code>2.2.6</code>, <code>2.2.8</code>, <code>2.2.9</code></em></p>
<p>Then I went through each version and determined the compatible modules for that version, and I&#8217;m pretty confident that I was also able to find each and every directive allowed by the compatible modules for that version (including core directives).  See <a href="http://www.askapache.com/htaccess/htaccess.html#htaccess-directives">.htaccess directive list</a>.</p>
<p>Basically I can now test a server using a variety of methods and determine almost 100% accurately what version of Apache (down to the API) is running, what modules (and versions) are enabled, and each and every directive that is allowed or disallowed for that version.</p>
<p>So this is so awesome because now we can enable all sorts of additional security features.</p>
<p>Other big changes are:</p>
<ul>
<li>Completely hands-off updates, so that updating the plugin keeps all your settings.</li>
<li>making each SID module have its own configuration and options (like protecting individual files, individual request, and custom exploit strings).</li>
<li>Advanced ErrorDocument usage and handling (like tracking repeat offenders and suggesting they be blocked, emailing admin with custom info, etc..)</li>
<li>Multi User/Group password Control</li>
</ul>
<p>And this time I am developing the plugin using a plethora of wordpress installations and configurations, to make sure that it will work regardless of a custom siteurl, blogid, etc..</p>
<p><strong>Release will come before 2009.. I have some vacations to take and business to finish first. </strong>
</p></blockquote>
<h2>.htaccess Security Modules</h2>
<h3><a id="htaccess-sid700" title="Directory Protection">Directory Protection</a></h3>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="http://www.askapache.com/htaccess/htaccess.html">Disable</a>]</p>
<pre>Options -Indexes
DirectoryIndex index.html index.php /index.php</pre>
<h3><a id="htaccess-sid800" title="Password Protect wp-login.php">Password Protect wp-login.php</a></h3>
<p>Requires a valid user/pass to access the login page <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
&nbsp;
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;</pre>
<h3><a id="htaccess-sid900" title="Password Protect wp-admin">Password Protect wp-admin</a></h3>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory. <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
&nbsp;
Order Deny,Allow
&nbsp;
Deny from All
Satisfy Any
&nbsp;
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&nbsp;
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$&quot;&gt;
Allow from All
&lt;/FilesMatch&gt;
&nbsp;
&lt;FilesMatch &quot;(async-upload)\.php$&quot;&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;</pre>
<h3><a id="htaccess-sid1000" title="Protect wp-content">Protect wp-content</a></h3>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1010" title="Protect wp-includes">Protect wp-includes</a></h3>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1011" title="Common Exploits">Common Exploits</a></h3>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1012" title="Stop Hotlinking">Stop Hotlinking</a></h3>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]</pre>
<h3><a id="htaccess-sid1015" title="Safe Request Methods">Safe Request Methods</a></h3>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a> <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1017" title="Forbid Proxies">Forbid Proxies</a></h3>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/" rel="nofollow" >Perishable Press</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1018" title="Real wp-comments-post.php">Real wp-comments-post.php</a></h3>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1019" title="HTTP PROTOCOL">HTTP PROTOCOL</a></h3>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only  <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1020" title="SPECIFY CHARACTERS">SPECIFY CHARACTERS</a></h3>
<p>Denies any request for a url containing characters other than &#8220;a-zA-Z0-9.+/-?=&#038;&#8221;  &#8211; REALLY helps but may break your site depending on your links. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1021" title="BAD Content Length">BAD Content Length</a></h3>
<p>Denies any POST request that doesnt have a Content-Length Header <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1022" title="BAD Content Type">BAD Content Type</a></h3>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1023" title="Directory Traversal">Directory Traversal</a></h3>
<p>Denies Requests containing ../ or ./. which is a directory traversal exploit attempt <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<h3><a id="htaccess-sid1024" title="PHPSESSID Cookie">PHPSESSID Cookie</a></h3>
<p>Only blocks when a PHPSESSID cookie is sent by the user and it contains characters other than 0-9a-z <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<h3><a id="htaccess-sid1025" title="NO HOST:">NO HOST:</a></h3>
<p>Denies requests that dont contain a HTTP HOST Header. <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1026" title="Bogus Graphics Exploit">Bogus Graphics Exploit</a></h3>
<p>Denies obvious exploit using bogus graphics  <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1027" title="No UserAgent, No Post">No UserAgent, No Post</a></h3>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1028" title="No Referer, No Comment">No Referer, No Comment</a></h3>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1029" title="Trackback Spam">Trackback Spam</a></h3>
<p>Denies obvious trackback spam.   See <a href="http://ocaoimh.ie/2008/07/03/more-ways-to-stop-spammers-and-unwanted-traffic/" rel="nofollow" >Holy Shmoly!</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1030" title="SSL-Only Site">SSL-Only Site</a></h3>
<p>Redirects all non-SSL (https) requests to your https-enabled url [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-301">301</a>]</p>
<h3><a id="htaccess-sid2000" title="Anti-Spam, Anti-Exploits">Anti-Spam, Anti-Exploits</a></h3>
<p>Denies Obvious Spam and uses advanced mod_security protection [<a href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html">Read More</a>]</p>
<h2>.htaccess Security Module Screenshot</h2>
<p><a rel="lb" href='http://uploads.askapache.com/2008/07/http-security-askapache.png'><img src="http://uploads.askapache.com/2008/07/http-security-askapache1.png" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" title="http-security-askapache1" /></a></p>
<p><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"></a><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html">.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Chmod, Umask, Stat, Fileperms, and File Permissions</title>
		<link>http://www.askapache.com/security/chmod-stat.html</link>
		<comments>http://www.askapache.com/security/chmod-stat.html#comments</comments>
		<pubDate>Wed, 19 Nov 2008 10:16:56 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[302 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[503]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash_profile]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[fifo]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[Fsockopen]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Sessions]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[umask]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1800</guid>
		<description><![CDATA[<p><a class="IFL" id="id8" href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html"></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe "grasp" isn't the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren't many instances when a computer user encounters them.  I've done a lot of research on it the past couple weeks...  and now here's everything I've learned so far.. cuz you guys <em>AskApache Regs</em> Rock! <br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/chmod-stat.html"class="IFL" id="id8" ></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe &#8220;grasp&#8221; isn&#8217;t the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren&#8217;t many instances when a computer user encounters them.   Windows has been trying to figure it out for decades with little progress, so don&#8217;t feel bad if you don&#8217;t know much about it.  <strong>Unless you&#8217;re with the program</strong> and running Mac or any other <a href="http://www.archlinux.org/" rel="nofollow" >BSD/Unix</a> based OS you&#8217;ve never had the ability to secure your system in this most basic and fundamental way.  Usually the first time someone encounters file permissions it&#8217;s because their website was cracked.. <br class="C" /></p>
<h3>.htaccess</h3>
<p><kbd>$ chmod 604 .htaccess</kbd></p>
<pre>604 -rw&#45;&#45;&#45;-r&#45;-  /home/askapache/cgi-bin/.htaccess</pre>
<h3>php.cgi</h3>
<p><kbd>$ chmod 711 php.cgi</kbd></p>
<pre>$ 711 -rwx&#45;-x&#45;-x  /home/askapache/cgi-bin/php.cgi</pre>
<h3>.php.ini</h3>
<p><kbd>$ chmod 600 php.ini</kbd></p>
<pre>$ 600 -rw&#45;&#45;-&#45;&#45;&#45;-  /home/askapache/cgi-bin/php.ini</pre>
<p>I&#8217;m in the process of developing an updated version of the .htaccess security plugin, and one thing I have been working on is file permissions.  Some people had problems trying to create files on their server and I realized it was bad programming on my part..  so I began researching permissions in detail. I went deep into the source code of Apache (<em>which is why this site is called AskApache, BTW</em>), PHP, Python, Ocaml, Perl, Ruby, and POSIX operating systems and got a pretty good handle on it now..</p>
<h2>Tips before we dig in</h2>
<p>Here&#8217;s a few things I&#8217;ve learned that I didn&#8217;t know before (using php).</p>
<h3>Deleting Files and Directories</h3>
<p>Deleting a file may require chmodding the file to 666 or even 777 before you are able to delete it.  You also might have to chmod the parent directory of the file as well.  Also, you may have to chdir to the directory the file is in.  And lastly you may have to change the owner or group of the file.  Further than that you can try renaming the file first then deleting it..</p>
<p>Deleting a directory means you need to remove every file in it first.  It needs to be empty.  And if your file system uses NFS or some other networked FS you might have even more problems deleting files.  If the file you are trying to delete is being used by say, Apache or php then you might have to kill that process first.</p>
<h3>Creating Files in Restrictive Environments</h3>
<p>My research has been geared to try and make my code as robust as possible, I&#8217;m throwing everything but the kitchen sink into some of these functions because so many people are on such different types of servers.  To create a file in a restrictive environment is a fun excercise to take.. You can write a file using many different functions, but there are some tricks if they all fail.  One trick is instead of trying to &#8220;write&#8221; the data to the file, you can UPLOAD the data to the server and let PHP handle the file as if you used an upload form.  I like to use fsockopen to do it, as some installations have been setup to prevent this type of fake upload.</p>
<p>Then there are the various other hacks like using an ftp connection (if you know the user/pass) to send the file from php, using ssh from php, whatever is available on the hosts php installation.  In addition to those more involved workarounds you can often get around this problem by doing little hacks discussed at php.net in the comments for various functions.  Such as changing the umask, changing directories with chdir first, creating a temporary file using a function like tempfile and then renaming or copying the tempfile to your desired file which sometimes gives you the permissions needed to write to the location.</p>
<p>If the php installation is newer than you can also look into creating your own stream context to pass write the data direct.</p>
<h2>Stat Function</h2>
<p>I&#8217;ve created a stat function in php that goes farther than the normal stat function&#8230; Just give the function a file to stat, and it returns an array of information.  </p>
<p>function askapache_stat($filename) {<br />
 clearstatcache();<br />
 $ss=@stat($filename);<br />
 if(!$ss) die(&#8220;Couldnt stat {$filename}&#8221;);<br />
 $file_convert=array(0140000=>&#8217;ssocket&#8217;,0120000=>&#8217;llink&#8217;,0100000=>&#8217;-file&#8217;,0060000=>&#8217;bblock&#8217;,0040000=>&#8217;ddir&#8217;,0020000=>&#8217;cchar&#8217;,0010000=>&#8217;pfifo&#8217;);<br />
 $p=$ss['mode'];<br />
 $t=decoct($ss['mode'] &#038; 0170000);<br />
 $str = (array_key_exists(octdec($t),$file_convert)) ? $file_convert[octdec($t)]{0} : &#8216;u&#8217;;<br />
 $str.=(($p&#038;0&#215;0100)?&#8217;r':&#8217;-').(($p&#038;0&#215;0080)?&#8217;w':&#8217;-').(($p&#038;0&#215;0040)?(($p&#038;0&#215;0800)?&#8217;s':&#8217;x'):(($p&#038;0&#215;0800)?&#8217;S':&#8217;-'));<br />
 $str.=(($p&#038;0&#215;0020)?&#8217;r':&#8217;-').(($p&#038;0&#215;0010)?&#8217;w':&#8217;-').(($p&#038;0&#215;0008)?(($p&#038;0&#215;0400)?&#8217;s':&#8217;x'):(($p&#038;0&#215;0400)?&#8217;S':&#8217;-'));<br />
 $str.=(($p&#038;0&#215;0004)?&#8217;r':&#8217;-').(($p&#038;0&#215;0002)?&#8217;w':&#8217;-').(($p&#038;0&#215;0001)?(($p&#038;0&#215;0200)?&#8217;t':&#8217;x'):(($p&#038;0&#215;0200)?&#8217;T':&#8217;-'));</p>
<p> $s=array(<br />
 &#8216;perms&#8217;=>array(<br />
  &#8216;umask&#8217;=>sprintf(&#8220;%04o&#8221;,umask()),<br />
  &#8216;human&#8217;=>$str,<br />
  &#8216;octal1&#8242;=>sprintf(&#8220;%o&#8221;, ($ss['mode'] &#038; 000777)),<br />
  &#8216;octal2&#8242;=>sprintf(&#8220;0%o&#8221;, 0777 &#038; $p),<br />
  &#8216;decimal&#8217;=>sprintf(&#8220;%04o&#8221;, $p),<br />
  &#8216;fileperms&#8217;=>@fileperms($filename),<br />
  &#8216;mode1&#8242;=>$p,<br />
  &#8216;mode2&#8242;=>$ss['mode']),</p>
<p> &#8216;filetype&#8217;=>array(<br />
  &#8216;type&#8217;=>substr($file_convert[octdec($t)],1),<br />
  &#8216;type_octal&#8217;=>sprintf(&#8220;%07o&#8221;, octdec($t)),<br />
  &#8216;is_file&#8217;=>@is_file($filename),<br />
  &#8216;is_dir&#8217;=>@is_dir($filename),<br />
  &#8216;is_link&#8217;=>@is_link($filename),<br />
  &#8216;is_readable&#8217;=> @is_readable($filename),<br />
  &#8216;is_writable&#8217;=> @is_writable($filename)),</p>
<p> &#8216;owner&#8217;=>array(<br />
  &#8216;fileowner&#8217;=>$ss['uid'],<br />
  &#8216;filegroup&#8217;=>$ss['gid'],<br />
  &#8216;owner_name&#8217;=>(function_exists(&#8216;posix_getpwuid&#8217;)) ? @reset(@posix_getpwuid($ss['uid'])) : &#8221;,<br />
  &#8216;group_name&#8217;=>(function_exists(&#8216;posix_getgrgid&#8217;)) ? @reset(@posix_getgrgid($ss['gid'])) : &#8221;),</p>
<p> &#8216;file&#8217;=>array(<br />
  &#8216;filename&#8217;=>$filename,<br />
  &#8216;realpath&#8217;=>(@realpath($filename) != $filename) ? @realpath($filename) : &#8221;,<br />
  &#8216;dirname&#8217;=>@dirname($filename),<br />
  &#8216;basename&#8217;=>@basename($filename)),</p>
<p> &#8216;device&#8217;=>array(<br />
  &#8216;device&#8217;=>$ss['dev'], //Device<br />
  &#8216;device_number&#8217;=>$ss['rdev'], //Device number, if device.<br />
  &#8216;inode&#8217;=>$ss['ino'], //File serial number<br />
  &#8216;link_count&#8217;=>$ss['nlink'], //link count<br />
  &#8216;link_to&#8217;=>($s['type']==&#8217;link&#8217;) ? @readlink($filename) : &#8221;),</p>
<p> &#8216;size&#8217;=>array(<br />
  &#8216;size&#8217;=>$ss['size'], //Size of file, in bytes.<br />
  &#8216;blocks&#8217;=>$ss['blocks'], //Number 512-byte blocks allocated<br />
  &#8216;block_size&#8217;=> $ss['blksize']), //Optimal block size for I/O.</p>
<p> &#8216;time&#8217;=>array(<br />
  &#8216;mtime&#8217;=>$ss['mtime'], //Time of last modification<br />
  &#8216;atime&#8217;=>$ss['atime'], //Time of last access.<br />
  &#8216;ctime&#8217;=>$ss['ctime'], //Time of last status change<br />
  &#8216;accessed&#8217;=>@date(&#8216;Y M D H:i:s&#8217;,$ss['atime']),<br />
  &#8216;modified&#8217;=>@date(&#8216;Y M D H:i:s&#8217;,$ss['mtime']),<br />
  &#8216;created&#8217;=>@date(&#8216;Y M D H:i:s&#8217;,$ss['ctime'])),<br />
 );</p>
<p> clearstatcache();<br />
 return $s;<br />
}
</pre>
<h3>PHP Stat Function Output</h2>
<p>Example output, say from <code>print_r(askapache_stat( __FILE__ ) );</code></p>
<p>Array(<br />
[perms] => Array<br />
  (<br />
  [umask] => 0022<br />
  [human] => -rw-r--r--<br />
  [octal1] => 644<br />
  [octal2] => 0644<br />
  [decimal] => 100644<br />
  [fileperms] => 33188<br />
  [mode1] => 33188<br />
  [mode2] => 33188<br />
  )</p>
<p>[filetype] => Array<br />
  (<br />
  [type] => file<br />
  [type_octal] => 0100000<br />
  [is_file] => 1<br />
  [is_dir] =><br />
  [is_link] =><br />
  [is_readable] => 1<br />
  [is_writable] => 1<br />
  )</p>
<p>[owner] => Array<br />
  (<br />
  [fileowner] => 035483<br />
  [filegroup] => 23472<br />
  [owner_name] => askapache<br />
  [group_name] => grp22558<br />
  )</p>
<p>[file] => Array<br />
  (<br />
  [filename] => /home/askapache/askapache-stat/public_html/ok/g.php<br />
  [realpath] =><br />
  [dirname] => /home/askapache/askapache-stat/public_html/ok<br />
  [basename] => g.php<br />
  )</p>
<p>[device] => Array<br />
  (<br />
  [device] => 25<br />
  [device_number] => 0<br />
  [inode] => 92455020<br />
  [link_count] => 1<br />
  [link_to] =><br />
  )</p>
<p>[size] => Array<br />
  (<br />
  [size] => 2652<br />
  [blocks] => 8<br />
  [block_size] => 8192<br />
  )</p>
<p>[time] => Array<br />
  (<br />
  [mtime] => 1227685253<br />
  [atime] => 1227685138<br />
  [ctime] => 1227685253<br />
  [accessed] => 2008 Nov Tue 23:38:58<br />
  [modified] => 2008 Nov Tue 23:40:53<br />
  [created] => 2008 Nov Tue 23:40:53<br />
  )<br />
)
</pre>
<h2><a id="chmod-0-to-7777"></a>Every Permission 0000 to 0777</h2>
<p><a href="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" rel="nofollow" class="IFL" ><img src="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" alt="chmod, umask, file permissions test" title="chmod, umask, file permissions test" /></a>This shows what each numeric permission does to a REGULAR file.  I'll provide the code to do this below so you can do the same thing on your server.<br class="C" /></p>
<dl class="dlsm" style="border-right:1px solid #CCC;">
<dt><kbd>chmod 0</kbd></dt>
<dd><code>----------</code></dd>
<dt><kbd>chmod 1</kbd></dt>
<dd><code>---------x</code></dd>
<dt><kbd>chmod 2</kbd></dt>
<dd><code>--------w-</code></dd>
<dt><kbd>chmod 3</kbd></dt>
<dd><code>--------wx</code></dd>
<dt><kbd>chmod 4</kbd></dt>
<dd><code>-------r--</code></dd>
<dt><kbd>chmod 5</kbd></dt>
<dd><code>-------r-x</code></dd>
<dt><kbd>chmod 6</kbd></dt>
<dd><code>-------rw-</code></dd>
<dt><kbd>chmod 7</kbd></dt>
<dd><code>-------rwx</code></dd>
<dt><kbd>chmod 10</kbd></dt>
<dd><code>------x---</code></dd>
<dt><kbd>chmod 11</kbd></dt>
<dd><code>------x--x</code></dd>
<dt><kbd>chmod 12</kbd></dt>
<dd><code>------x-w-</code></dd>
<dt><kbd>chmod 13</kbd></dt>
<dd><code>------x-wx</code></dd>
<dt><kbd>chmod 14</kbd></dt>
<dd><code>------xr--</code></dd>
<dt><kbd>chmod 15</kbd></dt>
<dd><code>------xr-x</code></dd>
<dt><kbd>chmod 16</kbd></dt>
<dd><code>------xrw-</code></dd>
<dt><kbd>chmod 17</kbd></dt>
<dd><code>------xrwx</code></dd>
<dt><kbd>chmod 20</kbd></dt>
<dd><code>-----w----</code></dd>
<dt><kbd>chmod 21</kbd></dt>
<dd><code>-----w---x</code></dd>
<dt><kbd>chmod 22</kbd></dt>
<dd><code>-----w--w-</code></dd>
<dt><kbd>chmod 23</kbd></dt>
<dd><code>-----w--wx</code></dd>
<dt><kbd>chmod 24</kbd></dt>
<dd><code>-----w-r--</code></dd>
<dt><kbd>chmod 25</kbd></dt>
<dd><code>-----w-r-x</code></dd>
<dt><kbd>chmod 26</kbd></dt>
<dd><code>-----w-rw-</code></dd>
<dt><kbd>chmod 27</kbd></dt>
<dd><code>-----w-rwx</code></dd>
<dt><kbd>chmod 30</kbd></dt>
<dd><code>-----wx---</code></dd>
<dt><kbd>chmod 31</kbd></dt>
<dd><code>-----wx--x</code></dd>
<dt><kbd>chmod 32</kbd></dt>
<dd><code>-----wx-w-</code></dd>
<dt><kbd>chmod 33</kbd></dt>
<dd><code>-----wx-wx</code></dd>
<dt><kbd>chmod 34</kbd></dt>
<dd><code>-----wxr--</code></dd>
<dt><kbd>chmod 35</kbd></dt>
<dd><code>-----wxr-x</code></dd>
<dt><kbd>chmod 36</kbd></dt>
<dd><code>-----wxrw-</code></dd>
<dt><kbd>chmod 37</kbd></dt>
<dd><code>-----wxrwx</code></dd>
<dt><kbd>chmod 40</kbd></dt>
<dd><code>----r-----</code></dd>
<dt><kbd>chmod 41</kbd></dt>
<dd><code>----r----x</code></dd>
<dt><kbd>chmod 42</kbd></dt>
<dd><code>----r---w-</code></dd>
<dt><kbd>chmod 43</kbd></dt>
<dd><code>----r---wx</code></dd>
<dt><kbd>chmod 44</kbd></dt>
<dd><code>----r--r--</code></dd>
<dt><kbd>chmod 45</kbd></dt>
<dd><code>----r--r-x</code></dd>
<dt><kbd>chmod 46</kbd></dt>
<dd><code>----r--rw-</code></dd>
<dt><kbd>chmod 47</kbd></dt>
<dd><code>----r--rwx</code></dd>
<dt><kbd>chmod 50</kbd></dt>
<dd><code>----r-x---</code></dd>
<dt><kbd>chmod 51</kbd></dt>
<dd><code>----r-x--x</code></dd>
<dt><kbd>chmod 52</kbd></dt>
<dd><code>----r-x-w-</code></dd>
<dt><kbd>chmod 53</kbd></dt>
<dd><code>----r-x-wx</code></dd>
<dt><kbd>chmod 54</kbd></dt>
<dd><code>----r-xr--</code></dd>
<dt><kbd>chmod 55</kbd></dt>
<dd><code>----r-xr-x</code></dd>
<dt><kbd>chmod 56</kbd></dt>
<dd><code>----r-xrw-</code></dd>
<dt><kbd>chmod 57</kbd></dt>
<dd><code>----r-xrwx</code></dd>
<dt><kbd>chmod 60</kbd></dt>
<dd><code>----rw----</code></dd>
<dt><kbd>chmod 61</kbd></dt>
<dd><code>----rw---x</code></dd>
<dt><kbd>chmod 62</kbd></dt>
<dd><code>----rw--w-</code></dd>
<dt><kbd>chmod 63</kbd></dt>
<dd><code>----rw--wx</code></dd>
<dt><kbd>chmod 64</kbd></dt>
<dd><code>----rw-r--</code></dd>
<dt><kbd>chmod 65</kbd></dt>
<dd><code>----rw-r-x</code></dd>
<dt><kbd>chmod 66</kbd></dt>
<dd><code>----rw-rw-</code></dd>
<dt><kbd>chmod 67</kbd></dt>
<dd><code>----rw-rwx</code></dd>
<dt><kbd>chmod 70</kbd></dt>
<dd><code>----rwx---</code></dd>
<dt><kbd>chmod 71</kbd></dt>
<dd><code>----rwx--x</code></dd>
<dt><kbd>chmod 72</kbd></dt>
<dd><code>----rwx-w-</code></dd>
<dt><kbd>chmod 73</kbd></dt>
<dd><code>----rwx-wx</code></dd>
<dt><kbd>chmod 74</kbd></dt>
<dd><code>----rwxr--</code></dd>
<dt><kbd>chmod 75</kbd></dt>
<dd><code>----rwxr-x</code></dd>
<dt><kbd>chmod 76</kbd></dt>
<dd><code>----rwxrw-</code></dd>
<dt><kbd>chmod 77</kbd></dt>
<dd><code>----rwxrwx</code></dd>
<dt><kbd>chmod 100</kbd></dt>
<dd><code>---x------</code></dd>
<dt><kbd>chmod 101</kbd></dt>
<dd><code>---x-----x</code></dd>
<dt><kbd>chmod 102</kbd></dt>
<dd><code>---x----w-</code></dd>
<dt><kbd>chmod 103</kbd></dt>
<dd><code>---x----wx</code></dd>
<dt><kbd>chmod 104</kbd></dt>
<dd><code>---x---r--</code></dd>
<dt><kbd>chmod 105</kbd></dt>
<dd><code>---x---r-x</code></dd>
<dt><kbd>chmod 106</kbd></dt>
<dd><code>---x---rw-</code></dd>
<dt><kbd>chmod 107</kbd></dt>
<dd><code>---x---rwx</code></dd>
<dt><kbd>chmod 110</kbd></dt>
<dd><code>---x--x---</code></dd>
<dt><kbd>chmod 111</kbd></dt>
<dd><code>---x--x--x</code></dd>
<dt><kbd>chmod 112</kbd></dt>
<dd><code>---x--x-w-</code></dd>
<dt><kbd>chmod 113</kbd></dt>
<dd><code>---x--x-wx</code></dd>
<dt><kbd>chmod 114</kbd></dt>
<dd><code>---x--xr--</code></dd>
<dt><kbd>chmod 115</kbd></dt>
<dd><code>---x--xr-x</code></dd>
<dt><kbd>chmod 116</kbd></dt>
<dd><code>---x--xrw-</code></dd>
<dt><kbd>chmod 117</kbd></dt>
<dd><code>---x--xrwx</code></dd>
<dt><kbd>chmod 120</kbd></dt>
<dd><code>---x-w----</code></dd>
<dt><kbd>chmod 121</kbd></dt>
<dd><code>---x-w---x</code></dd>
<dt><kbd>chmod 122</kbd></dt>
<dd><code>---x-w--w-</code></dd>
<dt><kbd>chmod 123</kbd></dt>
<dd><code>---x-w--wx</code></dd>
<dt><kbd>chmod 124</kbd></dt>
<dd><code>---x-w-r--</code></dd>
<dt><kbd>chmod 125</kbd></dt>
<dd><code>---x-w-r-x</code></dd>
<dt><kbd>chmod 126</kbd></dt>
<dd><code>---x-w-rw-</code></dd>
<dt><kbd>chmod 127</kbd></dt>
<dd><code>---x-w-rwx</code></dd>
<dt><kbd>chmod 130</kbd></dt>
<dd><code>---x-wx---</code></dd>
<dt><kbd>chmod 131</kbd></dt>
<dd><code>---x-wx--x</code></dd>
<dt><kbd>chmod 132</kbd></dt>
<dd><code>---x-wx-w-</code></dd>
<dt><kbd>chmod 133</kbd></dt>
<dd><code>---x-wx-wx</code></dd>
<dt><kbd>chmod 134</kbd></dt>
<dd><code>---x-wxr--</code></dd>
<dt><kbd>chmod 135</kbd></dt>
<dd><code>---x-wxr-x</code></dd>
<dt><kbd>chmod 136</kbd></dt>
<dd><code>---x-wxrw-</code></dd>
<dt><kbd>chmod 137</kbd></dt>
<dd><code>---x-wxrwx</code></dd>
<dt><kbd>chmod 140</kbd></dt>
<dd><code>---xr-----</code></dd>
<dt><kbd>chmod 141</kbd></dt>
<dd><code>---xr----x</code></dd>
<dt><kbd>chmod 142</kbd></dt>
<dd><code>---xr---w-</code></dd>
<dt><kbd>chmod 143</kbd></dt>
<dd><code>---xr---wx</code></dd>
<dt><kbd>chmod 144</kbd></dt>
<dd><code>---xr--r--</code></dd>
<dt><kbd>chmod 145</kbd></dt>
<dd><code>---xr--r-x</code></dd>
<dt><kbd>chmod 146</kbd></dt>
<dd><code>---xr--rw-</code></dd>
<dt><kbd>chmod 147</kbd></dt>
<dd><code>---xr--rwx</code></dd>
<dt><kbd>chmod 150</kbd></dt>
<dd><code>---xr-x---</code></dd>
<dt><kbd>chmod 151</kbd></dt>
<dd><code>---xr-x--x</code></dd>
<dt><kbd>chmod 152</kbd></dt>
<dd><code>---xr-x-w-</code></dd>
<dt><kbd>chmod 153</kbd></dt>
<dd><code>---xr-x-wx</code></dd>
<dt><kbd>chmod 154</kbd></dt>
<dd><code>---xr-xr--</code></dd>
<dt><kbd>chmod 155</kbd></dt>
<dd><code>---xr-xr-x</code></dd>
<dt><kbd>chmod 156</kbd></dt>
<dd><code>---xr-xrw-</code></dd>
<dt><kbd>chmod 157</kbd></dt>
<dd><code>---xr-xrwx</code></dd>
<dt><kbd>chmod 160</kbd></dt>
<dd><code>---xrw----</code></dd>
<dt><kbd>chmod 161</kbd></dt>
<dd><code>---xrw---x</code></dd>
<dt><kbd>chmod 162</kbd></dt>
<dd><code>---xrw--w-</code></dd>
<dt><kbd>chmod 163</kbd></dt>
<dd><code>---xrw--wx</code></dd>
<dt><kbd>chmod 164</kbd></dt>
<dd><code>---xrw-r--</code></dd>
<dt><kbd>chmod 165</kbd></dt>
<dd><code>---xrw-r-x</code></dd>
<dt><kbd>chmod 166</kbd></dt>
<dd><code>---xrw-rw-</code></dd>
<dt><kbd>chmod 167</kbd></dt>
<dd><code>---xrw-rwx</code></dd>
<dt><kbd>chmod 170</kbd></dt>
<dd><code>---xrwx---</code></dd>
<dt><kbd>chmod 171</kbd></dt>
<dd><code>---xrwx--x</code></dd>
<dt><kbd>chmod 172</kbd></dt>
<dd><code>---xrwx-w-</code></dd>
<dt><kbd>chmod 173</kbd></dt>
<dd><code>---xrwx-wx</code></dd>
<dt><kbd>chmod 174</kbd></dt>
<dd><code>---xrwxr--</code></dd>
<dt><kbd>chmod 175</kbd></dt>
<dd><code>---xrwxr-x</code></dd>
<dt><kbd>chmod 176</kbd></dt>
<dd><code>---xrwxrw-</code></dd>
<dt><kbd>chmod 177</kbd></dt>
<dd><code>---xrwxrwx</code></dd>
<dt><kbd>chmod 200</kbd></dt>
<dd><code>--w-------</code></dd>
<dt><kbd>chmod 201</kbd></dt>
<dd><code>--w------x</code></dd>
<dt><kbd>chmod 202</kbd></dt>
<dd><code>--w-----w-</code></dd>
<dt><kbd>chmod 203</kbd></dt>
<dd><code>--w-----wx</code></dd>
<dt><kbd>chmod 204</kbd></dt>
<dd><code>--w----r--</code></dd>
<dt><kbd>chmod 205</kbd></dt>
<dd><code>--w----r-x</code></dd>
<dt><kbd>chmod 206</kbd></dt>
<dd><code>--w----rw-</code></dd>
<dt><kbd>chmod 207</kbd></dt>
<dd><code>--w----rwx</code></dd>
<dt><kbd>chmod 210</kbd></dt>
<dd><code>--w---x---</code></dd>
<dt><kbd>chmod 211</kbd></dt>
<dd><code>--w---x--x</code></dd>
<dt><kbd>chmod 212</kbd></dt>
<dd><code>--w---x-w-</code></dd>
<dt><kbd>chmod 213</kbd></dt>
<dd><code>--w---x-wx</code></dd>
<dt><kbd>chmod 214</kbd></dt>
<dd><code>--w---xr--</code></dd>
<dt><kbd>chmod 215</kbd></dt>
<dd><code>--w---xr-x</code></dd>
<dt><kbd>chmod 216</kbd></dt>
<dd><code>--w---xrw-</code></dd>
<dt><kbd>chmod 217</kbd></dt>
<dd><code>--w---xrwx</code></dd>
<dt><kbd>chmod 220</kbd></dt>
<dd><code>--w--w----</code></dd>
<dt><kbd>chmod 221</kbd></dt>
<dd><code>--w--w---x</code></dd>
<dt><kbd>chmod 222</kbd></dt>
<dd><code>--w--w--w-</code></dd>
<dt><kbd>chmod 223</kbd></dt>
<dd><code>--w--w--wx</code></dd>
<dt><kbd>chmod 224</kbd></dt>
<dd><code>--w--w-r--</code></dd>
<dt><kbd>chmod 225</kbd></dt>
<dd><code>--w--w-r-x</code></dd>
<dt><kbd>chmod 226</kbd></dt>
<dd><code>--w--w-rw-</code></dd>
<dt><kbd>chmod 227</kbd></dt>
<dd><code>--w--w-rwx</code></dd>
<dt><kbd>chmod 230</kbd></dt>
<dd><code>--w--wx---</code></dd>
<dt><kbd>chmod 231</kbd></dt>
<dd><code>--w--wx--x</code></dd>
<dt><kbd>chmod 232</kbd></dt>
<dd><code>--w--wx-w-</code></dd>
<dt><kbd>chmod 233</kbd></dt>
<dd><code>--w--wx-wx</code></dd>
<dt><kbd>chmod 234</kbd></dt>
<dd><code>--w--wxr--</code></dd>
<dt><kbd>chmod 235</kbd></dt>
<dd><code>--w--wxr-x</code></dd>
<dt><kbd>chmod 236</kbd></dt>
<dd><code>--w--wxrw-</code></dd>
<dt><kbd>chmod 237</kbd></dt>
<dd><code>--w--wxrwx</code></dd>
<dt><kbd>chmod 240</kbd></dt>
<dd><code>--w-r-----</code></dd>
<dt><kbd>chmod 241</kbd></dt>
<dd><code>--w-r----x</code></dd>
<dt><kbd>chmod 242</kbd></dt>
<dd><code>--w-r---w-</code></dd>
<dt><kbd>chmod 243</kbd></dt>
<dd><code>--w-r---wx</code></dd>
<dt><kbd>chmod 244</kbd></dt>
<dd><code>--w-r--r--</code></dd>
<dt><kbd>chmod 245</kbd></dt>
<dd><code>--w-r--r-x</code></dd>
<dt><kbd>chmod 246</kbd></dt>
<dd><code>--w-r--rw-</code></dd>
<dt><kbd>chmod 247</kbd></dt>
<dd><code>--w-r--rwx</code></dd>
<dt><kbd>chmod 250</kbd></dt>
<dd><code>--w-r-x---</code></dd>
<dt><kbd>chmod 251</kbd></dt>
<dd><code>--w-r-x--x</code></dd>
<dt><kbd>chmod 252</kbd></dt>
<dd><code>--w-r-x-w-</code></dd>
<dt><kbd>chmod 253</kbd></dt>
<dd><code>--w-r-x-wx</code></dd>
<dt><kbd>chmod 254</kbd></dt>
<dd><code>--w-r-xr--</code></dd>
<dt><kbd>chmod 255</kbd></dt>
<dd><code>--w-r-xr-x</code></dd>
<dt><kbd>chmod 256</kbd></dt>
<dd><code>--w-r-xrw-</code></dd>
<dt><kbd>chmod 257</kbd></dt>
<dd><code>--w-r-xrwx</code></dd>
<dt><kbd>chmod 260</kbd></dt>
<dd><code>--w-rw----</code></dd>
<dt><kbd>chmod 261</kbd></dt>
<dd><code>--w-rw---x</code></dd>
<dt><kbd>chmod 262</kbd></dt>
<dd><code>--w-rw--w-</code></dd>
<dt><kbd>chmod 263</kbd></dt>
<dd><code>--w-rw--wx</code></dd>
<dt><kbd>chmod 264</kbd></dt>
<dd><code>--w-rw-r--</code></dd>
<dt><kbd>chmod 265</kbd></dt>
<dd><code>--w-rw-r-x</code></dd>
<dt><kbd>chmod 266</kbd></dt>
<dd><code>--w-rw-rw-</code></dd>
<dt><kbd>chmod 267</kbd></dt>
<dd><code>--w-rw-rwx</code></dd>
<dt><kbd>chmod 270</kbd></dt>
<dd><code>--w-rwx---</code></dd>
<dt><kbd>chmod 271</kbd></dt>
<dd><code>--w-rwx--x</code></dd>
<dt><kbd>chmod 272</kbd></dt>
<dd><code>--w-rwx-w-</code></dd>
<dt><kbd>chmod 273</kbd></dt>
<dd><code>--w-rwx-wx</code></dd>
<dt><kbd>chmod 274</kbd></dt>
<dd><code>--w-rwxr--</code></dd>
<dt><kbd>chmod 275</kbd></dt>
<dd><code>--w-rwxr-x</code></dd>
<dt><kbd>chmod 276</kbd></dt>
<dd><code>--w-rwxrw-</code></dd>
<dt><kbd>chmod 277</kbd></dt>
<dd><code>--w-rwxrwx</code></dd>
<dt><kbd>chmod 300</kbd></dt>
<dd><code>--wx------</code></dd>
<dt><kbd>chmod 301</kbd></dt>
<dd><code>--wx-----x</code></dd>
<dt><kbd>chmod 302</kbd></dt>
<dd><code>--wx----w-</code></dd>
<dt><kbd>chmod 303</kbd></dt>
<dd><code>--wx----wx</code></dd>
<dt><kbd>chmod 304</kbd></dt>
<dd><code>--wx---r--</code></dd>
<dt><kbd>chmod 305</kbd></dt>
<dd><code>--wx---r-x</code></dd>
<dt><kbd>chmod 306</kbd></dt>
<dd><code>--wx---rw-</code></dd>
<dt><kbd>chmod 307</kbd></dt>
<dd><code>--wx---rwx</code></dd>
<dt><kbd>chmod 310</kbd></dt>
<dd><code>--wx--x---</code></dd>
<dt><kbd>chmod 311</kbd></dt>
<dd><code>--wx--x--x</code></dd>
<dt><kbd>chmod 312</kbd></dt>
<dd><code>--wx--x-w-</code></dd>
<dt><kbd>chmod 313</kbd></dt>
<dd><code>--wx--x-wx</code></dd>
<dt><kbd>chmod 314</kbd></dt>
<dd><code>--wx--xr--</code></dd>
<dt><kbd>chmod 315</kbd></dt>
<dd><code>--wx--xr-x</code></dd>
<dt><kbd>chmod 316</kbd></dt>
<dd><code>--wx--xrw-</code></dd>
<dt><kbd>chmod 317</kbd></dt>
<dd><code>--wx--xrwx</code></dd>
<dt><kbd>chmod 320</kbd></dt>
<dd><code>--wx-w----</code></dd>
<dt><kbd>chmod 321</kbd></dt>
<dd><code>--wx-w---x</code></dd>
<dt><kbd>chmod 322</kbd></dt>
<dd><code>--wx-w--w-</code></dd>
<dt><kbd>chmod 323</kbd></dt>
<dd><code>--wx-w--wx</code></dd>
<dt><kbd>chmod 324</kbd></dt>
<dd><code>--wx-w-r--</code></dd>
<dt><kbd>chmod 325</kbd></dt>
<dd><code>--wx-w-r-x</code></dd>
<dt><kbd>chmod 326</kbd></dt>
<dd><code>--wx-w-rw-</code></dd>
<dt><kbd>chmod 327</kbd></dt>
<dd><code>--wx-w-rwx</code></dd>
<dt><kbd>chmod 330</kbd></dt>
<dd><code>--wx-wx---</code></dd>
<dt><kbd>chmod 331</kbd></dt>
<dd><code>--wx-wx--x</code></dd>
<dt><kbd>chmod 332</kbd></dt>
<dd><code>--wx-wx-w-</code></dd>
<dt><kbd>chmod 333</kbd></dt>
<dd><code>--wx-wx-wx</code></dd>
<dt><kbd>chmod 334</kbd></dt>
<dd><code>--wx-wxr--</code></dd>
<dt><kbd>chmod 335</kbd></dt>
<dd><code>--wx-wxr-x</code></dd>
<dt><kbd>chmod 336</kbd></dt>
<dd><code>--wx-wxrw-</code></dd>
<dt><kbd>chmod 337</kbd></dt>
<dd><code>--wx-wxrwx</code></dd>
<dt><kbd>chmod 340</kbd></dt>
<dd><code>--wxr-----</code></dd>
<dt><kbd>chmod 341</kbd></dt>
<dd><code>--wxr----x</code></dd>
<dt><kbd>chmod 342</kbd></dt>
<dd><code>--wxr---w-</code></dd>
<dt><kbd>chmod 343</kbd></dt>
<dd><code>--wxr---wx</code></dd>
<dt><kbd>chmod 344</kbd></dt>
<dd><code>--wxr--r--</code></dd>
<dt><kbd>chmod 345</kbd></dt>
<dd><code>--wxr--r-x</code></dd>
<dt><kbd>chmod 346</kbd></dt>
<dd><code>--wxr--rw-</code></dd>
<dt><kbd>chmod 347</kbd></dt>
<dd><code>--wxr--rwx</code></dd>
<dt><kbd>chmod 350</kbd></dt>
<dd><code>--wxr-x---</code></dd>
<dt><kbd>chmod 351</kbd></dt>
<dd><code>--wxr-x--x</code></dd>
<dt><kbd>chmod 352</kbd></dt>
<dd><code>--wxr-x-w-</code></dd>
<dt><kbd>chmod 353</kbd></dt>
<dd><code>--wxr-x-wx</code></dd>
<dt><kbd>chmod 354</kbd></dt>
<dd><code>--wxr-xr--</code></dd>
<dt><kbd>chmod 355</kbd></dt>
<dd><code>--wxr-xr-x</code></dd>
<dt><kbd>chmod 356</kbd></dt>
<dd><code>--wxr-xrw-</code></dd>
<dt><kbd>chmod 357</kbd></dt>
<dd><code>--wxr-xrwx</code></dd>
<dt><kbd>chmod 360</kbd></dt>
<dd><code>--wxrw----</code></dd>
<dt><kbd>chmod 361</kbd></dt>
<dd><code>--wxrw---x</code></dd>
<dt><kbd>chmod 362</kbd></dt>
<dd><code>--wxrw--w-</code></dd>
<dt><kbd>chmod 363</kbd></dt>
<dd><code>--wxrw--wx</code></dd>
<dt><kbd>chmod 364</kbd></dt>
<dd><code>--wxrw-r--</code></dd>
<dt><kbd>chmod 365</kbd></dt>
<dd><code>--wxrw-r-x</code></dd>
<dt><kbd>chmod 366</kbd></dt>
<dd><code>--wxrw-rw-</code></dd>
<dt><kbd>chmod 367</kbd></dt>
<dd><code>--wxrw-rwx</code></dd>
<dt><kbd>chmod 370</kbd></dt>
<dd><code>--wxrwx---</code></dd>
<dt><kbd>chmod 371</kbd></dt>
<dd><code>--wxrwx--x</code></dd>
<dt><kbd>chmod 372</kbd></dt>
<dd><code>--wxrwx-w-</code></dd>
<dt><kbd>chmod 373</kbd></dt>
<dd><code>--wxrwx-wx</code></dd>
<dt><kbd>chmod 374</kbd></dt>
<dd><code>--wxrwxr--</code></dd>
<dt><kbd>chmod 375</kbd></dt>
<dd><code>--wxrwxr-x</code></dd>
<dt><kbd>chmod 376</kbd></dt>
<dd><code>--wxrwxrw-</code></dd>
<dt><kbd>chmod 377</kbd></dt>
<dd><code>--wxrwxrwx</code></dd>
</dl>
<dl class="dlsm FL">
<dt><kbd>chmod 400</kbd></dt>
<dd><code>-r--------</code></dd>
<dt><kbd>chmod 401</kbd></dt>
<dd><code>-r-------x</code></dd>
<dt><kbd>chmod 402</kbd></dt>
<dd><code>-r------w-</code></dd>
<dt><kbd>chmod 403</kbd></dt>
<dd><code>-r------wx</code></dd>
<dt><kbd>chmod 404</kbd></dt>
<dd><code>-r-----r--</code></dd>
<dt><kbd>chmod 405</kbd></dt>
<dd><code>-r-----r-x</code></dd>
<dt><kbd>chmod 406</kbd></dt>
<dd><code>-r-----rw-</code></dd>
<dt><kbd>chmod 407</kbd></dt>
<dd><code>-r-----rwx</code></dd>
<dt><kbd>chmod 410</kbd></dt>
<dd><code>-r----x---</code></dd>
<dt><kbd>chmod 411</kbd></dt>
<dd><code>-r----x--x</code></dd>
<dt><kbd>chmod 412</kbd></dt>
<dd><code>-r----x-w-</code></dd>
<dt><kbd>chmod 413</kbd></dt>
<dd><code>-r----x-wx</code></dd>
<dt><kbd>chmod 414</kbd></dt>
<dd><code>-r----xr--</code></dd>
<dt><kbd>chmod 415</kbd></dt>
<dd><code>-r----xr-x</code></dd>
<dt><kbd>chmod 416</kbd></dt>
<dd><code>-r----xrw-</code></dd>
<dt><kbd>chmod 417</kbd></dt>
<dd><code>-r----xrwx</code></dd>
<dt><kbd>chmod 420</kbd></dt>
<dd><code>-r---w----</code></dd>
<dt><kbd>chmod 421</kbd></dt>
<dd><code>-r---w---x</code></dd>
<dt><kbd>chmod 422</kbd></dt>
<dd><code>-r---w--w-</code></dd>
<dt><kbd>chmod 423</kbd></dt>
<dd><code>-r---w--wx</code></dd>
<dt><kbd>chmod 424</kbd></dt>
<dd><code>-r---w-r--</code></dd>
<dt><kbd>chmod 425</kbd></dt>
<dd><code>-r---w-r-x</code></dd>
<dt><kbd>chmod 426</kbd></dt>
<dd><code>-r---w-rw-</code></dd>
<dt><kbd>chmod 427</kbd></dt>
<dd><code>-r---w-rwx</code></dd>
<dt><kbd>chmod 430</kbd></dt>
<dd><code>-r---wx---</code></dd>
<dt><kbd>chmod 431</kbd></dt>
<dd><code>-r---wx--x</code></dd>
<dt><kbd>chmod 432</kbd></dt>
<dd><code>-r---wx-w-</code></dd>
<dt><kbd>chmod 433</kbd></dt>
<dd><code>-r---wx-wx</code></dd>
<dt><kbd>chmod 434</kbd></dt>
<dd><code>-r---wxr--</code></dd>
<dt><kbd>chmod 435</kbd></dt>
<dd><code>-r---wxr-x</code></dd>
<dt><kbd>chmod 436</kbd></dt>
<dd><code>-r---wxrw-</code></dd>
<dt><kbd>chmod 437</kbd></dt>
<dd><code>-r---wxrwx</code></dd>
<dt><kbd>chmod 440</kbd></dt>
<dd><code>-r--r-----</code></dd>
<dt><kbd>chmod 441</kbd></dt>
<dd><code>-r--r----x</code></dd>
<dt><kbd>chmod 442</kbd></dt>
<dd><code>-r--r---w-</code></dd>
<dt><kbd>chmod 443</kbd></dt>
<dd><code>-r--r---wx</code></dd>
<dt><kbd>chmod 444</kbd></dt>
<dd><code>-r--r--r--</code></dd>
<dt><kbd>chmod 445</kbd></dt>
<dd><code>-r--r--r-x</code></dd>
<dt><kbd>chmod 446</kbd></dt>
<dd><code>-r--r--rw-</code></dd>
<dt><kbd>chmod 447</kbd></dt>
<dd><code>-r--r--rwx</code></dd>
<dt><kbd>chmod 450</kbd></dt>
<dd><code>-r--r-x---</code></dd>
<dt><kbd>chmod 451</kbd></dt>
<dd><code>-r--r-x--x</code></dd>
<dt><kbd>chmod 452</kbd></dt>
<dd><code>-r--r-x-w-</code></dd>
<dt><kbd>chmod 453</kbd></dt>
<dd><code>-r--r-x-wx</code></dd>
<dt><kbd>chmod 454</kbd></dt>
<dd><code>-r--r-xr--</code></dd>
<dt><kbd>chmod 455</kbd></dt>
<dd><code>-r--r-xr-x</code></dd>
<dt><kbd>chmod 456</kbd></dt>
<dd><code>-r--r-xrw-</code></dd>
<dt><kbd>chmod 457</kbd></dt>
<dd><code>-r--r-xrwx</code></dd>
<dt><kbd>chmod 460</kbd></dt>
<dd><code>-r--rw----</code></dd>
<dt><kbd>chmod 461</kbd></dt>
<dd><code>-r--rw---x</code></dd>
<dt><kbd>chmod 462</kbd></dt>
<dd><code>-r--rw--w-</code></dd>
<dt><kbd>chmod 463</kbd></dt>
<dd><code>-r--rw--wx</code></dd>
<dt><kbd>chmod 464</kbd></dt>
<dd><code>-r--rw-r--</code></dd>
<dt><kbd>chmod 465</kbd></dt>
<dd><code>-r--rw-r-x</code></dd>
<dt><kbd>chmod 466</kbd></dt>
<dd><code>-r--rw-rw-</code></dd>
<dt><kbd>chmod 467</kbd></dt>
<dd><code>-r--rw-rwx</code></dd>
<dt><kbd>chmod 470</kbd></dt>
<dd><code>-r--rwx---</code></dd>
<dt><kbd>chmod 471</kbd></dt>
<dd><code>-r--rwx--x</code></dd>
<dt><kbd>chmod 472</kbd></dt>
<dd><code>-r--rwx-w-</code></dd>
<dt><kbd>chmod 473</kbd></dt>
<dd><code>-r--rwx-wx</code></dd>
<dt><kbd>chmod 474</kbd></dt>
<dd><code>-r--rwxr--</code></dd>
<dt><kbd>chmod 475</kbd></dt>
<dd><code>-r--rwxr-x</code></dd>
<dt><kbd>chmod 476</kbd></dt>
<dd><code>-r--rwxrw-</code></dd>
<dt><kbd>chmod 477</kbd></dt>
<dd><code>-r--rwxrwx</code></dd>
<dt><kbd>chmod 500</kbd></dt>
<dd><code>-r-x------</code></dd>
<dt><kbd>chmod 501</kbd></dt>
<dd><code>-r-x-----x</code></dd>
<dt><kbd>chmod 502</kbd></dt>
<dd><code>-r-x----w-</code></dd>
<dt><kbd>chmod 503</kbd></dt>
<dd><code>-r-x----wx</code></dd>
<dt><kbd>chmod 504</kbd></dt>
<dd><code>-r-x---r--</code></dd>
<dt><kbd>chmod 505</kbd></dt>
<dd><code>-r-x---r-x</code></dd>
<dt><kbd>chmod 506</kbd></dt>
<dd><code>-r-x---rw-</code></dd>
<dt><kbd>chmod 507</kbd></dt>
<dd><code>-r-x---rwx</code></dd>
<dt><kbd>chmod 510</kbd></dt>
<dd><code>-r-x--x---</code></dd>
<dt><kbd>chmod 511</kbd></dt>
<dd><code>-r-x--x--x</code></dd>
<dt><kbd>chmod 512</kbd></dt>
<dd><code>-r-x--x-w-</code></dd>
<dt><kbd>chmod 513</kbd></dt>
<dd><code>-r-x--x-wx</code></dd>
<dt><kbd>chmod 514</kbd></dt>
<dd><code>-r-x--xr--</code></dd>
<dt><kbd>chmod 515</kbd></dt>
<dd><code>-r-x--xr-x</code></dd>
<dt><kbd>chmod 516</kbd></dt>
<dd><code>-r-x--xrw-</code></dd>
<dt><kbd>chmod 517</kbd></dt>
<dd><code>-r-x--xrwx</code></dd>
<dt><kbd>chmod 520</kbd></dt>
<dd><code>-r-x-w----</code></dd>
<dt><kbd>chmod 521</kbd></dt>
<dd><code>-r-x-w---x</code></dd>
<dt><kbd>chmod 522</kbd></dt>
<dd><code>-r-x-w--w-</code></dd>
<dt><kbd>chmod 523</kbd></dt>
<dd><code>-r-x-w--wx</code></dd>
<dt><kbd>chmod 524</kbd></dt>
<dd><code>-r-x-w-r--</code></dd>
<dt><kbd>chmod 525</kbd></dt>
<dd><code>-r-x-w-r-x</code></dd>
<dt><kbd>chmod 526</kbd></dt>
<dd><code>-r-x-w-rw-</code></dd>
<dt><kbd>chmod 527</kbd></dt>
<dd><code>-r-x-w-rwx</code></dd>
<dt><kbd>chmod 530</kbd></dt>
<dd><code>-r-x-wx---</code></dd>
<dt><kbd>chmod 531</kbd></dt>
<dd><code>-r-x-wx--x</code></dd>
<dt><kbd>chmod 532</kbd></dt>
<dd><code>-r-x-wx-w-</code></dd>
<dt><kbd>chmod 533</kbd></dt>
<dd><code>-r-x-wx-wx</code></dd>
<dt><kbd>chmod 534</kbd></dt>
<dd><code>-r-x-wxr--</code></dd>
<dt><kbd>chmod 535</kbd></dt>
<dd><code>-r-x-wxr-x</code></dd>
<dt><kbd>chmod 536</kbd></dt>
<dd><code>-r-x-wxrw-</code></dd>
<dt><kbd>chmod 537</kbd></dt>
<dd><code>-r-x-wxrwx</code></dd>
<dt><kbd>chmod 540</kbd></dt>
<dd><code>-r-xr-----</code></dd>
<dt><kbd>chmod 541</kbd></dt>
<dd><code>-r-xr----x</code></dd>
<dt><kbd>chmod 542</kbd></dt>
<dd><code>-r-xr---w-</code></dd>
<dt><kbd>chmod 543</kbd></dt>
<dd><code>-r-xr---wx</code></dd>
<dt><kbd>chmod 544</kbd></dt>
<dd><code>-r-xr--r--</code></dd>
<dt><kbd>chmod 545</kbd></dt>
<dd><code>-r-xr--r-x</code></dd>
<dt><kbd>chmod 546</kbd></dt>
<dd><code>-r-xr--rw-</code></dd>
<dt><kbd>chmod 547</kbd></dt>
<dd><code>-r-xr--rwx</code></dd>
<dt><kbd>chmod 550</kbd></dt>
<dd><code>-r-xr-x---</code></dd>
<dt><kbd>chmod 551</kbd></dt>
<dd><code>-r-xr-x--x</code></dd>
<dt><kbd>chmod 552</kbd></dt>
<dd><code>-r-xr-x-w-</code></dd>
<dt><kbd>chmod 553</kbd></dt>
<dd><code>-r-xr-x-wx</code></dd>
<dt><kbd>chmod 554</kbd></dt>
<dd><code>-r-xr-xr--</code></dd>
<dt><kbd>chmod 555</kbd></dt>
<dd><code>-r-xr-xr-x</code></dd>
<dt><kbd>chmod 556</kbd></dt>
<dd><code>-r-xr-xrw-</code></dd>
<dt><kbd>chmod 557</kbd></dt>
<dd><code>-r-xr-xrwx</code></dd>
<dt><kbd>chmod 560</kbd></dt>
<dd><code>-r-xrw----</code></dd>
<dt><kbd>chmod 561</kbd></dt>
<dd><code>-r-xrw---x</code></dd>
<dt><kbd>chmod 562</kbd></dt>
<dd><code>-r-xrw--w-</code></dd>
<dt><kbd>chmod 563</kbd></dt>
<dd><code>-r-xrw--wx</code></dd>
<dt><kbd>chmod 564</kbd></dt>
<dd><code>-r-xrw-r--</code></dd>
<dt><kbd>chmod 565</kbd></dt>
<dd><code>-r-xrw-r-x</code></dd>
<dt><kbd>chmod 566</kbd></dt>
<dd><code>-r-xrw-rw-</code></dd>
<dt><kbd>chmod 567</kbd></dt>
<dd><code>-r-xrw-rwx</code></dd>
<dt><kbd>chmod 570</kbd></dt>
<dd><code>-r-xrwx---</code></dd>
<dt><kbd>chmod 571</kbd></dt>
<dd><code>-r-xrwx--x</code></dd>
<dt><kbd>chmod 572</kbd></dt>
<dd><code>-r-xrwx-w-</code></dd>
<dt><kbd>chmod 573</kbd></dt>
<dd><code>-r-xrwx-wx</code></dd>
<dt><kbd>chmod 574</kbd></dt>
<dd><code>-r-xrwxr--</code></dd>
<dt><kbd>chmod 575</kbd></dt>
<dd><code>-r-xrwxr-x</code></dd>
<dt><kbd>chmod 576</kbd></dt>
<dd><code>-r-xrwxrw-</code></dd>
<dt><kbd>chmod 577</kbd></dt>
<dd><code>-r-xrwxrwx</code></dd>
<dt><kbd>chmod 600</kbd></dt>
<dd><code>-rw-------</code></dd>
<dt><kbd>chmod 601</kbd></dt>
<dd><code>-rw------x</code></dd>
<dt><kbd>chmod 602</kbd></dt>
<dd><code>-rw-----w-</code></dd>
<dt><kbd>chmod 603</kbd></dt>
<dd><code>-rw-----wx</code></dd>
<dt><kbd>chmod 604</kbd></dt>
<dd><code>-rw----r--</code></dd>
<dt><kbd>chmod 605</kbd></dt>
<dd><code>-rw----r-x</code></dd>
<dt><kbd>chmod 606</kbd></dt>
<dd><code>-rw----rw-</code></dd>
<dt><kbd>chmod 607</kbd></dt>
<dd><code>-rw----rwx</code></dd>
<dt><kbd>chmod 610</kbd></dt>
<dd><code>-rw---x---</code></dd>
<dt><kbd>chmod 611</kbd></dt>
<dd><code>-rw---x--x</code></dd>
<dt><kbd>chmod 612</kbd></dt>
<dd><code>-rw---x-w-</code></dd>
<dt><kbd>chmod 613</kbd></dt>
<dd><code>-rw---x-wx</code></dd>
<dt><kbd>chmod 614</kbd></dt>
<dd><code>-rw---xr--</code></dd>
<dt><kbd>chmod 615</kbd></dt>
<dd><code>-rw---xr-x</code></dd>
<dt><kbd>chmod 616</kbd></dt>
<dd><code>-rw---xrw-</code></dd>
<dt><kbd>chmod 617</kbd></dt>
<dd><code>-rw---xrwx</code></dd>
<dt><kbd>chmod 620</kbd></dt>
<dd><code>-rw--w----</code></dd>
<dt><kbd>chmod 621</kbd></dt>
<dd><code>-rw--w---x</code></dd>
<dt><kbd>chmod 622</kbd></dt>
<dd><code>-rw--w--w-</code></dd>
<dt><kbd>chmod 623</kbd></dt>
<dd><code>-rw--w--wx</code></dd>
<dt><kbd>chmod 624</kbd></dt>
<dd><code>-rw--w-r--</code></dd>
<dt><kbd>chmod 625</kbd></dt>
<dd><code>-rw--w-r-x</code></dd>
<dt><kbd>chmod 626</kbd></dt>
<dd><code>-rw--w-rw-</code></dd>
<dt><kbd>chmod 627</kbd></dt>
<dd><code>-rw--w-rwx</code></dd>
<dt><kbd>chmod 630</kbd></dt>
<dd><code>-rw--wx---</code></dd>
<dt><kbd>chmod 631</kbd></dt>
<dd><code>-rw--wx--x</code></dd>
<dt><kbd>chmod 632</kbd></dt>
<dd><code>-rw--wx-w-</code></dd>
<dt><kbd>chmod 633</kbd></dt>
<dd><code>-rw--wx-wx</code></dd>
<dt><kbd>chmod 634</kbd></dt>
<dd><code>-rw--wxr--</code></dd>
<dt><kbd>chmod 635</kbd></dt>
<dd><code>-rw--wxr-x</code></dd>
<dt><kbd>chmod 636</kbd></dt>
<dd><code>-rw--wxrw-</code></dd>
<dt><kbd>chmod 637</kbd></dt>
<dd><code>-rw--wxrwx</code></dd>
<dt><kbd>chmod 640</kbd></dt>
<dd><code>-rw-r-----</code></dd>
<dt><kbd>chmod 641</kbd></dt>
<dd><code>-rw-r----x</code></dd>
<dt><kbd>chmod 642</kbd></dt>
<dd><code>-rw-r---w-</code></dd>
<dt><kbd>chmod 643</kbd></dt>
<dd><code>-rw-r---wx</code></dd>
<dt><kbd>chmod 644</kbd></dt>
<dd><code>-rw-r--r--</code></dd>
<dt><kbd>chmod 645</kbd></dt>
<dd><code>-rw-r--r-x</code></dd>
<dt><kbd>chmod 646</kbd></dt>
<dd><code>-rw-r--rw-</code></dd>
<dt><kbd>chmod 647</kbd></dt>
<dd><code>-rw-r--rwx</code></dd>
<dt><kbd>chmod 650</kbd></dt>
<dd><code>-rw-r-x---</code></dd>
<dt><kbd>chmod 651</kbd></dt>
<dd><code>-rw-r-x--x</code></dd>
<dt><kbd>chmod 652</kbd></dt>
<dd><code>-rw-r-x-w-</code></dd>
<dt><kbd>chmod 653</kbd></dt>
<dd><code>-rw-r-x-wx</code></dd>
<dt><kbd>chmod 654</kbd></dt>
<dd><code>-rw-r-xr--</code></dd>
<dt><kbd>chmod 655</kbd></dt>
<dd><code>-rw-r-xr-x</code></dd>
<dt><kbd>chmod 656</kbd></dt>
<dd><code>-rw-r-xrw-</code></dd>
<dt><kbd>chmod 657</kbd></dt>
<dd><code>-rw-r-xrwx</code></dd>
<dt><kbd>chmod 660</kbd></dt>
<dd><code>-rw-rw----</code></dd>
<dt><kbd>chmod 661</kbd></dt>
<dd><code>-rw-rw---x</code></dd>
<dt><kbd>chmod 662</kbd></dt>
<dd><code>-rw-rw--w-</code></dd>
<dt><kbd>chmod 663</kbd></dt>
<dd><code>-rw-rw--wx</code></dd>
<dt><kbd>chmod 664</kbd></dt>
<dd><code>-rw-rw-r--</code></dd>
<dt><kbd>chmod 665</kbd></dt>
<dd><code>-rw-rw-r-x</code></dd>
<dt><kbd>chmod 666</kbd></dt>
<dd><code>-rw-rw-rw-</code></dd>
<dt><kbd>chmod 667</kbd></dt>
<dd><code>-rw-rw-rwx</code></dd>
<dt><kbd>chmod 670</kbd></dt>
<dd><code>-rw-rwx---</code></dd>
<dt><kbd>chmod 671</kbd></dt>
<dd><code>-rw-rwx--x</code></dd>
<dt><kbd>chmod 672</kbd></dt>
<dd><code>-rw-rwx-w-</code></dd>
<dt><kbd>chmod 673</kbd></dt>
<dd><code>-rw-rwx-wx</code></dd>
<dt><kbd>chmod 674</kbd></dt>
<dd><code>-rw-rwxr--</code></dd>
<dt><kbd>chmod 675</kbd></dt>
<dd><code>-rw-rwxr-x</code></dd>
<dt><kbd>chmod 676</kbd></dt>
<dd><code>-rw-rwxrw-</code></dd>
<dt><kbd>chmod 677</kbd></dt>
<dd><code>-rw-rwxrwx</code></dd>
<dt><kbd>chmod 700</kbd></dt>
<dd><code>-rwx------</code></dd>
<dt><kbd>chmod 701</kbd></dt>
<dd><code>-rwx-----x</code></dd>
<dt><kbd>chmod 702</kbd></dt>
<dd><code>-rwx----w-</code></dd>
<dt><kbd>chmod 703</kbd></dt>
<dd><code>-rwx----wx</code></dd>
<dt><kbd>chmod 704</kbd></dt>
<dd><code>-rwx---r--</code></dd>
<dt><kbd>chmod 705</kbd></dt>
<dd><code>-rwx---r-x</code></dd>
<dt><kbd>chmod 706</kbd></dt>
<dd><code>-rwx---rw-</code></dd>
<dt><kbd>chmod 707</kbd></dt>
<dd><code>-rwx---rwx</code></dd>
<dt><kbd>chmod 710</kbd></dt>
<dd><code>-rwx--x---</code></dd>
<dt><kbd>chmod 711</kbd></dt>
<dd><code>-rwx--x--x</code></dd>
<dt><kbd>chmod 712</kbd></dt>
<dd><code>-rwx--x-w-</code></dd>
<dt><kbd>chmod 713</kbd></dt>
<dd><code>-rwx--x-wx</code></dd>
<dt><kbd>chmod 714</kbd></dt>
<dd><code>-rwx--xr--</code></dd>
<dt><kbd>chmod 715</kbd></dt>
<dd><code>-rwx--xr-x</code></dd>
<dt><kbd>chmod 716</kbd></dt>
<dd><code>-rwx--xrw-</code></dd>
<dt><kbd>chmod 717</kbd></dt>
<dd><code>-rwx--xrwx</code></dd>
<dt><kbd>chmod 720</kbd></dt>
<dd><code>-rwx-w----</code></dd>
<dt><kbd>chmod 721</kbd></dt>
<dd><code>-rwx-w---x</code></dd>
<dt><kbd>chmod 722</kbd></dt>
<dd><code>-rwx-w--w-</code></dd>
<dt><kbd>chmod 723</kbd></dt>
<dd><code>-rwx-w--wx</code></dd>
<dt><kbd>chmod 724</kbd></dt>
<dd><code>-rwx-w-r--</code></dd>
<dt><kbd>chmod 725</kbd></dt>
<dd><code>-rwx-w-r-x</code></dd>
<dt><kbd>chmod 726</kbd></dt>
<dd><code>-rwx-w-rw-</code></dd>
<dt><kbd>chmod 727</kbd></dt>
<dd><code>-rwx-w-rwx</code></dd>
<dt><kbd>chmod 730</kbd></dt>
<dd><code>-rwx-wx---</code></dd>
<dt><kbd>chmod 731</kbd></dt>
<dd><code>-rwx-wx--x</code></dd>
<dt><kbd>chmod 732</kbd></dt>
<dd><code>-rwx-wx-w-</code></dd>
<dt><kbd>chmod 733</kbd></dt>
<dd><code>-rwx-wx-wx</code></dd>
<dt><kbd>chmod 734</kbd></dt>
<dd><code>-rwx-wxr--</code></dd>
<dt><kbd>chmod 735</kbd></dt>
<dd><code>-rwx-wxr-x</code></dd>
<dt><kbd>chmod 736</kbd></dt>
<dd><code>-rwx-wxrw-</code></dd>
<dt><kbd>chmod 737</kbd></dt>
<dd><code>-rwx-wxrwx</code></dd>
<dt><kbd>chmod 740</kbd></dt>
<dd><code>-rwxr-----</code></dd>
<dt><kbd>chmod 741</kbd></dt>
<dd><code>-rwxr----x</code></dd>
<dt><kbd>chmod 742</kbd></dt>
<dd><code>-rwxr---w-</code></dd>
<dt><kbd>chmod 743</kbd></dt>
<dd><code>-rwxr---wx</code></dd>
<dt><kbd>chmod 744</kbd></dt>
<dd><code>-rwxr--r--</code></dd>
<dt><kbd>chmod 745</kbd></dt>
<dd><code>-rwxr--r-x</code></dd>
<dt><kbd>chmod 746</kbd></dt>
<dd><code>-rwxr--rw-</code></dd>
<dt><kbd>chmod 747</kbd></dt>
<dd><code>-rwxr--rwx</code></dd>
<dt><kbd>chmod 750</kbd></dt>
<dd><code>-rwxr-x---</code></dd>
<dt><kbd>chmod 751</kbd></dt>
<dd><code>-rwxr-x--x</code></dd>
<dt><kbd>chmod 752</kbd></dt>
<dd><code>-rwxr-x-w-</code></dd>
<dt><kbd>chmod 753</kbd></dt>
<dd><code>-rwxr-x-wx</code></dd>
<dt><kbd>chmod 754</kbd></dt>
<dd><code>-rwxr-xr--</code></dd>
<dt><kbd>chmod 755</kbd></dt>
<dd><code>-rwxr-xr-x</code></dd>
<dt><kbd>chmod 756</kbd></dt>
<dd><code>-rwxr-xrw-</code></dd>
<dt><kbd>chmod 757</kbd></dt>
<dd><code>-rwxr-xrwx</code></dd>
<dt><kbd>chmod 760</kbd></dt>
<dd><code>-rwxrw----</code></dd>
<dt><kbd>chmod 761</kbd></dt>
<dd><code>-rwxrw---x</code></dd>
<dt><kbd>chmod 762</kbd></dt>
<dd><code>-rwxrw--w-</code></dd>
<dt><kbd>chmod 763</kbd></dt>
<dd><code>-rwxrw--wx</code></dd>
<dt><kbd>chmod 764</kbd></dt>
<dd><code>-rwxrw-r--</code></dd>
<dt><kbd>chmod 765</kbd></dt>
<dd><code>-rwxrw-r-x</code></dd>
<dt><kbd>chmod 766</kbd></dt>
<dd><code>-rwxrw-rw-</code></dd>
<dt><kbd>chmod 767</kbd></dt>
<dd><code>-rwxrw-rwx</code></dd>
<dt><kbd>chmod 770</kbd></dt>
<dd><code>-rwxrwx---</code></dd>
<dt><kbd>chmod 771</kbd></dt>
<dd><code>-rwxrwx--x</code></dd>
<dt><kbd>chmod 772</kbd></dt>
<dd><code>-rwxrwx-w-</code></dd>
<dt><kbd>chmod 773</kbd></dt>
<dd><code>-rwxrwx-wx</code></dd>
<dt><kbd>chmod 774</kbd></dt>
<dd><code>-rwxrwxr--</code></dd>
<dt><kbd>chmod 775</kbd></dt>
<dd><code>-rwxrwxr-x</code></dd>
<dt><kbd>chmod 776</kbd></dt>
<dd><code>-rwxrwxrw-</code></dd>
<dt><kbd>chmod 777</kbd></dt>
<dd><code>-rwxrwxrwx</code></dd>
</dl>
<h2>Congratulations!</h2>
<p>Here's my custom stat function, which I am definately not finished with, so check back in a couple days and if you find any improvements please hook me up with a comment!</p>
<p>function askapache_stat( $filename ) {<br />
$p=@fileperms($filename);<br />
$s=@stat($filename);<br />
$str='';<br />
$t=decoct($s['mode'] &#038; 0170000);</p>
<p>switch (octdec($t)) {<br />
case 0140000: $str = 's'; $stat['type']='socket'; break;<br />
case 0120000: $str = 'l'; $stat['type']='link'; break;<br />
case 0100000: $str = '-'; $stat['type']='file'; break;<br />
case 0060000: $str = 'b'; $stat['type']='block'; break;<br />
case 0040000: $str = 'd'; $stat['type']='dir'; break;<br />
case 0020000: $str = 'c'; $stat['type']='char'; break;<br />
case 0010000: $str = 'p'; $stat['type']='fifo'; break;<br />
default: $str = 'u'; $stat['type']='unknown'; break;<br />
}</p>
<p>$stat['type_octal'] = sprintf("%07o", octdec($t));</p>
<p>$str .= (($p&#038;0x0100)?'r':'-').(($p&#038;0x0080)?'w':'-').(($p&#038;0x0040)?(($p&#038;0x0800)?'s':'x'):(($p&#038;0x0800)?'S':'-'));<br />
$str .= (($p&#038;0x0020)?'r':'-').(($p&#038;0x0010)?'w':'-').(($p&#038;0x0008)?(($p&#038;0x0400)?'s':'x'):(($p&#038;0x0400)?'S':'-'));<br />
$str .= (($p&#038;0x0004)?'r':'-').(($p&#038;0x0002)?'w':'-').(($p&#038;0x0001)?(($p&#038;0x0200)?'t':'x'):(($p&#038;0x0200)?'T':'-'));</p>
<p>$stat['default_umask']=sprintf("%04o",umask());<br />
$stat['perm_human']=$str;<br />
$stat['perm_octal1'] = sprintf( "%o", ( $s['mode'] &#038; 00777 ) );<br />
$stat['perm_octal2'] = sprintf("0%o", 0777 &#038; $p);<br />
$stat['perm_dec'] = sprintf("%04o", $p);<br />
$stat['perm_mode']=$s['mode'];	 // File mode.</p>
<p>$stat['file'] = @realpath($filename);<br />
$stat['basename'] = basename( $filename );</p>
<p>$stat['user_id'] = $s['uid'];<br />
$stat['group_id'] = $s['gid'];</p>
<p>$stat['device']=$s['dev'];			// Device<br />
$stat['device_number']=$s['rdev'];		// Device number, if device.<br />
$stat['inode']=$s['ino'];			// File serial number<br />
$stat['link_count']=$s['nlink'];		// link count<br />
if($stat['type']=='link')$stat['link_to']=@readlink( $filename );</p>
<p>$stat['size']=$s['size'];		// Size of file, in bytes.<br />
$stat['block_size']=$s['blksize'];	// Optimal block size for I/O.<br />
$stat['blocks']=$s['blocks'];	// Number 512-byte blocks allocated</p>
<p>$stat['time_access']=@date( 'Y M D H:i:s',$s['atime']);		// Time of last access.<br />
$stat['time_modified']=@date( 'Y M D H:i:s',$s['mtime']);		// Time of last modification<br />
$stat['time_created']=@date( 'Y M D H:i:s',$s['ctime']);		// Time of last status change</p>
<p>clearstatcache();<br />
return $stat;<br />
}</p>
<p>header('Content-Type: text/plain');<br />
$stat=askapache_stat(__FILE__);<br />
print_r($stat);
</pre>
<h3>Defining Permission Bits</h3>
<p>!defined('S_IFMT') &#038;&#038; define('S_IFMT', 0170000); //	mask for all types<br />
!defined('S_IFSOCK') &#038;&#038; define('S_IFSOCK', 0140000); // type: socket<br />
!defined('S_IFLNK') &#038;&#038; define('S_IFLNK', 0120000); // type:	symbolic link<br />
!defined('S_IFREG') &#038;&#038; define('S_IFREG', 0100000); // type:	regular file<br />
!defined('S_IFBLK') &#038;&#038; define('S_IFBLK', 0060000); // type:	block device<br />
!defined('S_IFDIR') &#038;&#038; define('S_IFDIR', 0040000); // type:	directory<br />
!defined('S_IFCHR') &#038;&#038; define('S_IFCHR', 0020000); // type:	character device<br />
!defined('S_IFIFO') &#038;&#038; define('S_IFIFO', 0010000); // type:	fifo</p>
<p>!defined('S_ISUID') &#038;&#038; define('S_ISUID', 0004000); // set-uid bit<br />
!defined('S_ISGID') &#038;&#038; define('S_ISGID', 0002000); // set-gid bit<br />
!defined('S_ISVTX') &#038;&#038; define('S_ISVTX', 0001000); // sticky bit<br />
!defined('S_IRWXU') &#038;&#038; define('S_IRWXU', 00700); //	mask for owner permissions<br />
!defined('S_IRUSR') &#038;&#038; define('S_IRUSR', 00400); //	owner: read permission<br />
!defined('S_IWUSR') &#038;&#038; define('S_IWUSR', 00200); //	owner: write permission<br />
!defined('S_IXUSR') &#038;&#038; define('S_IXUSR', 00100); //	owner: execute permission<br />
!defined('S_IRWXG') &#038;&#038; define('S_IRWXG', 00070); //	mask for group permissions<br />
!defined('S_IRGRP') &#038;&#038; define('S_IRGRP', 00040); //	group: read permission<br />
!defined('S_IWGRP') &#038;&#038; define('S_IWGRP', 00020); //	group: write permission<br />
!defined('S_IXGRP') &#038;&#038; define('S_IXGRP', 00010); //	group: execute permission<br />
!defined('S_IRWXO') &#038;&#038; define('S_IRWXO', 00007); //	mask for others permissions<br />
!defined('S_IROTH') &#038;&#038; define('S_IROTH', 00004); //	others:	read permission<br />
!defined('S_IWOTH') &#038;&#038; define('S_IWOTH', 00002); //	others:	write permission<br />
!defined('S_IXOTH') &#038;&#038; define('S_IXOTH', 00001); //	others:	execute permission</p>
<p>!defined('S_IRWXUGO') &#038;&#038; define('S_IRWXUGO', (S_IRWXU | S_IRWXG | S_IRWXO));<br />
!defined('S_IALLUGO') &#038;&#038; define('S_IALLUGO', (S_ISUID | S_ISGID | S_ISVTX | S_IRWXUGO));<br />
!defined('S_IRUGO') &#038;&#038; define('S_IRUGO', (S_IRUSR | S_IRGRP | S_IROTH));<br />
!defined('S_IWUGO') &#038;&#038; define('S_IWUGO', (S_IWUSR | S_IWGRP | S_IWOTH));<br />
!defined('S_IXUGO') &#038;&#038; define('S_IXUGO', (S_IXUSR | S_IXGRP | S_IXOTH));<br />
!defined('S_IRWUGO') &#038;&#038; define('S_IRWUGO', (S_IRUGO | S_IWUGO));
</pre>
<h2>How File Permissions Work</h2>
<p>When PHP is installed on your server by you or whoever runs the server, it uses the file permissions that are used by the Operating System running the server..  If you are smart or just lucky than you are running some type of BSD/Unix/Solaris/Linux/Sun based Operating system and PHP won't have any problems.  If you are running on a Locked, proprietary OS like Windows, PHP will still work but it has to use a lot of shortcuts and hacks to basically "Pretend" to act like the OS is BSD/Unix, and some key features just won't be available.</p>
<h2>The OS Permission Bits</h2>
<p>Here's the file permissions my Linux server uses, and which PHP automatically uses.  The code basically just defines the default permissions for files, and defines the file atributes for each file that you can access by using the stat function, which I've improved upon to make things easier.</p>
<p>Download: <a href='http://uploads.askapache.com/2008/11/stat.h' title="POSIX Standard: 5.6 File Characteristics">POSIX Standard: 5.6 File Characteristics<code>sys/stat.h</code></a></p>
<h3>Protection bits for File Owner</h3>
<pre>#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100</pre>
<h3>Protection bits for File Group</h3>
<pre>#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010</pre>
<h3>Protection bits for All Others</h3>
<pre>#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001</pre>
<h2>Some Example Permissions</h2>
<p><code>0477</code>  // owner has read only, other and group has rwx<br />
<code>0677</code>  // owner has rw only, other and group has rwx</p>
<p><code>0444</code>  // all have read only<br />
<code>0666</code>  // all have rw only</p>
<p><code>0400</code>  // owner has read only, group and others have no permission<br />
<code>0600</code> // owner has rw only, group and others have no permission</p>
<p><code>0470</code>  // owner has read only, group has rwx, others have no permission<br />
<code>0407</code>  // owner has read only, other has rwx, group has no permission</p>
<p><code>0670</code>  // owner has rw only, group has rwx, others have no permission<br />
<code>0607</code>  // owner has rw only, group has no permission and others have rwx</p>
<h2>What's a File</h2>
<p>A file is not merely its contents, a name, and a file type. A file also has an owner (a user ID), a group (a group ID), permissions (what the owner can do with the file, what people in the group can do, and what everyone else can do), various timestamps, and other information. Collectively, we call these a file's attributes.</p>
<h2>Structure of File Mode Bits</h2>
<p>The file mode bits have two parts: the file permission bits, which control ordinary access to the file, and special mode bits, which affect only some files.</p>
<p>There are three kinds of permissions that a user can have for a file:</p>
<ol>
<li>permission to read the file. For directories, this means permission to list the contents of the directory.</li>
<li>permission to write to (change) the file. For directories, this means permission to create and remove files in the directory.</li>
<li>permission to execute the file (run it as a program). For directories, this means permission to access files in the directory.</li>
</ol>
<p>There are three categories of users who may have different permissions to perform any of the above operations on a file:</p>
<ol>
<li>the file's owner.</li>
<li>other users who are in the file's group</li>
<li>everyone else.</li>
</ol>
<p>Files are given an owner and group when they are created. Usually the owner is the current user and the group is the group of the directory the file is in, but this varies with the operating system, the file system the file is created on, and the way the file is created. You can change the owner and group of a file by using the <strong>chown</strong> and <strong>chgrp</strong> commands.</p>
<p>In addition to the three sets of three permissions listed above, the file mode bits have three special components, which affect only executable files (programs) and, on most systems, directories:</p>
<ol>
<li>Set the process's effective user ID to that of the file upon execution (called the set-user-ID bit, or sometimes the setuid bit). For directories on a few systems, give files created in the directory the same owner as the directory, no matter who creates them, and set the set-user-ID bit of newly-created subdirectories.</li>
<li>Set the process's effective group ID to that of the file upon execution (called the set-group-ID bit, or sometimes the setgid bit). For directories on most systems, give files created in the directory the same group as the directory, no matter what group the user who creates them is in, and set the set-group-ID bit of newly-created subdirectories.</li>
<li>Prevent unprivileged users from removing or renaming a file in a directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.</li>
</ol>
<p>For regular files on some older systems, save the program's text image on the swap device so it will load more quickly when run; this is called the <code>sticky bit</code>.</p>
<h2>Setting Permissions</h2>
<p>The basic symbolic operations on a file's permissions are adding, removing, and setting the permission that certain users have to read, write, and execute or search the file. These operations have the following format:</p>
<p><code>users operation permissions</code></p>
<p>The spaces between the three parts above are shown for readability only; symbolic modes cannot contain spaces.  The users part tells which users' access to the file is changed. It consists of one or more of the following letters (or it can be empty). When more than one of these letters is given, the order that they are in does not matter.</p>
<ul>
<li><strong>u</strong> - the user who owns the file.</li>
<li><strong>g</strong> - other users who are in the file's group.</li>
<li><strong>o</strong> - all other users.</li>
<li><strong>a</strong> - all users; the same as ugo.</li>
</ul>
<p>The operation part tells how to change the affected users' access to the file, and is one of the following symbols:</p>
<ul>
<li><strong>+</strong> - to add the permissions to whatever permissions the users already have for the file.</li>
<li><strong>-</strong> - to remove the permissions from whatever permissions the users already have for the file.</li>
<li><strong>=</strong> - to make the permissions the only permissions that the users have for the file.</li>
</ul>
<p>The permissions part tells what kind of access to the file should be changed; it is normally zero or more of the following letters. As with the users part, the order does not matter when more than one letter is given. Omitting the permissions part is useful only with the = operation, where it gives the specified users no access at all to the file.</p>
<ul>
<li><strong>r</strong> - the permission the users have to read the file.</li>
<li><strong>w</strong> - the permission the users have to write to the file.</li>
<li><strong>x</strong> - the permission the users have to execute the file, or search it if it is a directory.</li>
</ul>
<p>For example, to give everyone permission to read and write a regular file, but not to execute it, use:</p>
<pre>a=rw</pre>
<p>To remove write permission for all users other than the file's owner, use:</p>
<pre>go-w</pre>
<p>The above command does not affect the access that the owner of the file has to it, nor does it affect whether other users can read or execute the file.</p>
<p>To give everyone except a file's owner no permission to do anything with that file, use the mode below. Other users could still remove the file, if they have write permission on the directory it is in.</p>
<pre>go=</pre>
<p>Another way to specify the same thing is:</p>
<pre>og-rwx</pre>
<h2>Copying Existing Permissions</h2>
<p>You can base a file's permissions on its existing permissions. To do this, instead of using a series of <strong>r, w, or x</strong> letters after the operator, you use the letter <strong>u, g, or o</strong>. For example, the mode</p>
<pre>o+g</pre>
<p>adds the permissions for users who are in a file's group to the permissions that other users have for the file. Thus, if the file started out as mode 664 (rw-rw-r--), the above mode would change it to mode 666 (rw-rw-rw-). If the file had started out as mode 741 (rwxr----x), the above mode would change it to mode 745 (rwxr--r-x). The - and = operations work analogously.</p>
<h2>Umask and Protection</h2>
<p>If the users part of a symbolic mode is omitted, it defaults to a (affect all users), except that any permissions that are set in the system variable umask are not affected. The value of umask can be set using the umask command. Its default value varies from system to system.</p>
<p>Omitting the users part of a symbolic mode is generally not useful with operations other than +. It is useful with + because it allows you to use umask as an easily customizable protection against giving away more permission to files than you intended to.  As an example, if umask has the value 2, which removes write permission for users who are not in the file's group, then the mode:</p>
<pre>+w</pre>
<p>adds permission to write to the file to its owner and to other users who are in the file's group, but not to other users. In contrast, the mode:</p>
<pre>a+w</pre>
<p>ignores umask, and does give write permission for the file to all users.</p>
<h2>Directories, Set-User-ID and Set-Group-ID Bits</h2>
<p>On most systems, if a directory's set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. On a few systems, a directory's set-user-ID bit has a similar effect on the ownership of new subfiles and the set-user-ID bits of new subdirectories. These mechanisms let users share files more easily, by lessening the need to use chmod or chown to share new files.</p>
<p>These convenience mechanisms rely on the set-user-ID and set-group-ID bits of directories. If commands like chmod and mkdir routinely cleared these bits on directories, the mechanisms would be less convenient and it would be harder to share files. Therefore, a command like chmod does not affect the set-user-ID or set-group-ID bits of a directory unless the user specifically mentions them in a symbolic mode, or sets them in a numeric mode. For example, on systems that support set-group-ID inheritance:</p>
<pre># These commands leave the set-user-ID and
# set-group-ID bits of the subdirectories alone,
# so that they retain their default values.
mkdir A B C
chmod 755 A
chmod 0755 B
chmod u=rwx,go=rx C
mkdir -m 755 D
mkdir -m 0755 E
mkdir -m u=rwx,go=rx F</pre>
<p>If you want to try to set these bits, you must mention them explicitly in the symbolic or numeric modes, e.g.:</p>
<pre># These commands try to set the set-user-ID
# and set-group-ID bits of the subdirectories.
mkdir G H
chmod 6755 G
chmod u=rwx,go=rx,a+s H
mkdir -m 6755 I
mkdir -m u=rwx,go=rx,a+s J</pre>
<p>If you want to try to clear these bits, you must mention them explicitly in a symbolic mode, e.g.:</p>
<pre># This command tries to clear the set-user-ID
# and set-group-ID bits of the directory D.
chmod a-s D</pre>
<h2>Numeric Modes</h2>
<p>The permissions granted to the user, to other users in the file's group, and to other users not in the file's group each require three bits, which are represented as one octal digit. The three special mode bits also require one bit each, and they are as a group represented as another octal digit. Here is how the bits are arranged, starting with the lowest valued bit:</p>
<h3>Other users not in the file's group:</h3>
<pre>1 Execute/search
2 Write
4 Read</pre>
<h3>Other users in the file's group:</h3>
<pre>10 Execute/search
20 Write
40 Read</pre>
<h3>The file's owner:</h3>
<pre>100 Execute/search
200 Write
400 Read</pre>
<h3>Special mode bits:</h3>
<pre>1000 Restricted deletion flag or sticky bit
2000 Set group ID on execution
4000 Set user ID on execution</pre>
<p>For example, numeric <code>mode 4755</code> corresponds to symbolic mode <code>u=rwxs,go=rx</code>, and numeric m<code>ode 664</code> corresponds to symbolic mode <code>ug=rw,o=r</code>. Numeric <code>mode 0</code> corresponds to symbolic mode <code>a=</code>.</p>
<h2>Apache's Internal Bits (hex)</h2>
<pre>#define APR_FPROT_USETID   0x8000 /* Set user id */
#define APR_FPROT_UREAD   0x0400 /* Read by user */
#define APR_FPROT_UWRITE   0x0200 /* Write by user */
#define APR_FPROT_UEXECUTE 0x0100 /* Execute by user */
&nbsp;
#define APR_FPROT_GSETID   0x4000 /* Set group id */
#define APR_FPROT_GREAD   0x0040 /* Read by group */
#define APR_FPROT_GWRITE   0x0020 /* Write by group */
#define APR_FPROT_GEXECUTE 0x0010 /* Execute by group */
&nbsp;
#define APR_FPROT_WSTICKY 0x2000 /* Sticky bit */
#define APR_FPROT_WREAD   0x0004 /* Read by others */
#define APR_FPROT_WWRITE 0x0002 /* Write by others */
#define APR_FPROT_WEXECUTE 0x0001 /* Execute by others */
&nbsp;
#define APR_FPROT_OS_DEFAULT  0x0FFF /* use OS&#039;s default permissions */
&nbsp;
/* additional permission flags for apr_file_copy  and apr_file_append */
#define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /* Copy source file&#039;s permissions */</pre>
<p>Download: <a href='http://uploads.askapache.com/2008/11/fileacc.c' title="A file to put ALL of the accessor functions for apr_file_t types"><code>httpd-2.2.10/srclib/apr/file_io/unix/fileacc.c</code></a> Here's some interesting bitmasking done by Apache that uses the defined bits set earlier by stat.h</p>
<pre>apr_unix_perms2mode(perms){
 mode=0;
 if (perms &amp; APR_USETID) mode |= S_ISUID;
 if (perms &amp; APR_UREAD)  mode |= S_IRUSR;
 if (perms &amp; APR_UWRITE) mode |= S_IWUSR;
 if (perms &amp; APR_UEXECUTE) mode |= S_IXUSR;
&nbsp;
 if (perms &amp; APR_GSETID) mode |= S_ISGID;
 if (perms &amp; APR_GREAD)  mode |= S_IRGRP;
 if (perms &amp; APR_GWRITE) mode |= S_IWGRP;
 if (perms &amp; APR_GEXECUTE) mode |= S_IXGRP;
&nbsp;
 if (perms &amp; APR_WSTICKY) mode |= S_ISVTX;
 if (perms &amp; APR_WREAD)  mode |= S_IROTH;
 if (perms &amp; APR_WWRITE) mode |= S_IWOTH;
 if (perms &amp; APR_WEXECUTE) mode |= S_IXOTH;
 return mode;
}
&nbsp;
apr_unix_mode2perms(mode){
 perms = 0;
 if (mode &amp; S_ISUID)perms |= APR_USETID;
 if (mode &amp; S_IRUSR)perms |= APR_UREAD;
 if (mode &amp; S_IWUSR)perms |= APR_UWRITE;
 if (mode &amp; S_IXUSR)perms |= APR_UEXECUTE;
&nbsp;
 if (mode &amp; S_ISGID)perms |= APR_GSETID;
 if (mode &amp; S_IRGRP)perms |= APR_GREAD;
 if (mode &amp; S_IWGRP)perms |= APR_GWRITE;
 if (mode &amp; S_IXGRP)perms |= APR_GEXECUTE;
&nbsp;
 if (mode &amp; S_ISVTX)perms |= APR_WSTICKY;
 if (mode &amp; S_IROTH)perms |= APR_WREAD;
 if (mode &amp; S_IWOTH)perms |= APR_WWRITE;
 if (mode &amp; S_IXOTH)perms |= APR_WEXECUTE;
 return perms;
}</pre>
<h2>umask</h2>
<pre>umask(int mask){
 arg1;
 int oldumask;
 int arg_count = ZEND_NUM_ARGS();
 oldumask = umask(077);
&nbsp;
 if (BG(umask) == -1) BG(umask) = oldumask;
 if (arg_count == 0) umask(oldumask);
&nbsp;
 convert_to_long_ex(arg1);
 umask(Z_LVAL_PP(arg1));
 RETURN_LONG(oldumask);
}</pre>
<h2>File Attributes</h2>
<p>Each file will have attributes based on the type of OS.. Using the stat command you can view them.</p>
<h3>Viewing stat results</h3>
<pre>* %a - Access rights in octal
* %A - Access rights in human readable form
* %b - Number of blocks allocated (see %B)
* %B - The size in bytes of each block reported by %b
* %d - Device number in decimal
* %D - Device number in hex
* %f - Raw mode in hex
* %F - File type
* %g - Group ID of owner
* %G - Group name of owner
* %h - Number of hard links
* %i - Inode number
* %n - File name
* %N - Quoted file name with dereference if symbolic link
* %o - I/O block size
* %s - Total size, in bytes
* %t - Major device type in hex
* %T - Minor device type in hex
* %u - User ID of owner
* %U - User name of owner
* %x - Time of last access
* %X - Time of last access as seconds since Epoch
* %y - Time of last modification
* %Y - Time of last modification as seconds since Epoch
* %z - Time of last change
* %Z - Time of last change as seconds since Epoch</pre>
<h2>The OS Attribute Bits</h2>
<p>These defined values are what allows your operating system to determine the type of file being accessed. </p>
<pre>#define S_IFMT   00170000  /* These bits determine file type. */
#define S_IFSOCK 0140000  /* Socket file */
#define S_IFLNK   0120000  /* Symbolic Link */
#define S_IFREG   0100000  /* Regular file */
#define S_IFDIR   0040000  /* Directory */
#define S_IFIFO  0010000   /* FIFO first-in-first-out file */
&nbsp;
/* Such devices can be read either a character at a time or a &quot;block&quot; (many characters) at a time,
hence we say there are block special files and character special files. */
#define S_IFBLK   0060000  /* Block device */
#define S_IFCHR  0020000  /* Character device */</pre>
<h3>Special Permission Bits</h3>
<pre>#define S_ISUID  0004000  /* Set user ID on execution.  */
#define S_ISGID  0002000  /* Set group ID on execution.  */
#define S_ISVTX  0001000 /* Save swapped text after use (sticky).  */</pre>
<h3>Bitmasking to determine Filetype</h3>
<pre>#define S_ISLNK(m) (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) &amp; S_IFMT) == S_IFSOCK)</pre>
<h3>Default Permission Masks</h3>
<pre>#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
#define S_IRUGO  (S_IRUSR|S_IRGRP|S_IROTH)
#define S_IWUGO  (S_IWUSR|S_IWGRP|S_IWOTH)
#define S_IXUGO  (S_IXUSR|S_IXGRP|S_IXOTH)</pre>
<p>Download: <a href='http://uploads.askapache.com/2008/11/filestat.c' title="handles file stat"><code>httpd-2.2.10/srclib/apr/file_io/unix/filestat.c</code></a>, this file shows a simple way to determine the type of file.</p>
<pre>filetype_from_mode(mode){
 type;
 switch (mode &amp; S_IFMT) {
  case S_IFREG:  type = APR_REG;  break;
  case S_IFDIR:  type = APR_DIR;  break;
  case S_IFLNK:  type = APR_LNK;  break;
&nbsp;
  case S_IFCHR:  type = APR_CHR;  break;
  case S_IFBLK:  type = APR_BLK;  break;
  case S_IFFIFO: type = APR_PIPE; break;
  case S_IFSOCK: type = APR_SOCK; break;
  default: type = APR_UNKFILE;
 }
 return type;
}</pre>
<h3>Apache Stat Bits</h3>
<pre>#define APR_FINFO_LINK  0x00000001 /* Stat the link not the file itself if it is a link */
#define APR_FINFO_MTIME  0x00000010 /* Modification Time */
#define APR_FINFO_CTIME  0x00000020 /* Creation or inode-changed time */
#define APR_FINFO_ATIME  0x00000040 /* Access Time */
#define APR_FINFO_SIZE  0x00000100 /* Size of the file */
#define APR_FINFO_CSIZE  0x00000200 /* Storage size consumed by the file */
#define APR_FINFO_DEV  0x00001000 /* Device */
#define APR_FINFO_INODE  0x00002000 /* Inode */
#define APR_FINFO_NLINK  0x00004000 /* Number of links */
#define APR_FINFO_TYPE  0x00008000 /* Type */
#define APR_FINFO_USER  0x00010000 /* User */
#define APR_FINFO_GROUP  0x00020000 /* Group */
#define APR_FINFO_UPROT  0x00100000 /* User protection bits */
#define APR_FINFO_GPROT  0x00200000 /* Group protection bits */
#define APR_FINFO_WPROT  0x00400000 /* World protection bits */
#define APR_FINFO_ICASE  0x01000000 /* if dev is case insensitive */
#define APR_FINFO_NAME  0x02000000 /* name in proper case */
#define APR_FINFO_MIN  0x00008170 /* type, mtime, ctime, atime, size */
#define APR_FINFO_IDENT  0x00003000 /* dev and inode */
#define APR_FINFO_OWNER  0x00030000 /* user and group */
#define APR_FINFO_PROT  0x00700000 /* all protections */
#define APR_FINFO_NORM  0x0073b170 /* an atomic unix apr_stat() */
#define APR_FINFO_DIRENT 0x02000000 /* an atomic unix apr_dir_read() */</pre>
<h3>The Apache file information structure.</h3>
<pre>apr_uid_t user;  /* The user id that owns the file */
apr_gid_t group;  /* The group id that owns the file */
apr_ino_t inode; /* The inode of the file. */
apr_dev_t device; /* The id of the device the file is on. */
apr_int32_t nlink; /* The number of hard links to the file. */
apr_off_t size;  /* The size of the file */
apr_off_t csize; /* The storage size consumed by the file */
apr_time_t atime; /* The time the file was last accessed */
apr_time_t mtime; /* The time the file was last modified */
apr_time_t ctime; /* The time the file was created, or the inode was last changed */
const char *fname; /* The pathname of the file (possibly unrooted) */
const char *name; /* The file&#039;s name (no path) in filesystem case */</pre>
<h3>File Time Attributes</h3>
<blockquote><h3><a href="http://php.net/manual/en/function.touch.php" rel="nofollow" >touch</a></</p>
<p>If changing both the access and modification times to the current time, touch can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.</p>
<p>Although touch provides options for changing two of the times the times of last access and modification of a file, there is actually a third one as well: the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.</p>
</blockquote>
<p><a name="Shared_hosting_user_security"></a></p>
<h2>Shared hosting user security </h2>
<ul>
<li><a href="#Shared_hosting_user_security" rel="nofollow" >Shared hosting user security</a></li>
<li><a href="#Apache_Security" rel="nofollow" >Apache Security</a></li>
<li><a href="#Multiuser_security_setup_example" rel="nofollow" >Multiuser security setup example</a></li>
<li><a href="#SSH_key_fingerprints" rel="nofollow" >SSH key fingerprints</a></li>
<li><a href="#External_Links" rel="nofollow" >External Links</a></li>
</ul>
<p>WebHost allows you to create multiple users per account. Each user can have domain assigned to its home home directory accessible via FTP or SSH/SCP. The problem with multiple users on the same account is that they share the same default unix group, and default permissions allow their files to be easily modified by the members of this group. Usually this doesn't pose a problem as each user is probably trusted by account owner to not to mess with others files, but if one of the users have their web application hacked then all other users on the same account will be in danger. </p>
<p>By default all files in your account are created with 644 privileges and directories are with 775. That means any user can read your files and any user from the same account can move and add files in your freshly made directories. Your home directory is different, though. By default it carries 751 attribute meaning that only members of your group can see your files, but can't add any new. These group access schemes are possible, because every user in your account has its primary/default group set to "pgxxxxxx", which is assigned to every new file you create by default. The normal way to secure users from web-intrusion is to assign a separate group to the web-server user, removing it from default group. This way, exploited scripts will not be able to traverse into home directories of other users on your account. To allow account users to update centralized web-site they could be added to web-site group explicitly. But this "normal way" doesn't work with DreamHost, because you can't delete web-user from the default group and unless you set access for every new file explicitly, it will be possible for an intruder to read it. </p>
<p>To make managing privileges easier in interactive sessions "umask 007" command can be specified in your .bash_profile - this makes all new files carry xx0 mask. You also need to control your scripts (web based or cron/shell) so that they set mask for critical files explicitly. To secure account users from access by means of hacked user script you would also like to define another group for every user in your account and change group ownership of the user's home directory to that group with "set gid" bit set (and optional umask 007 in .bash_profile). </p>
<p>Therefore, to secure your users from web-intrusion you need to: </p>
<ol>
<li>Add a separate user and group for every domain where apache will be running </li>
<li>Add a separate group for other user accounts </li>
<li>Change the default group for new files created by your users by changing the group of their home directory and setting "set gid" bit for it (it is impossible to do this with FTP accounts, therefore you will need to login in each account via SSH) </li>
<li>Add users who need access to web-site into the web-user group </li>
<li>Optionally set umask 007 in .bash_profile for every user to tweak default WebHost775/664 permissions to something like 770/660 for directories and files that are not meant to be read by Apache (660 could also be used for all web scripts including .php as they are not read by dhapache CGI, but merely executed) </li>
</ol>
<h2><a name="Apache_Security"></a>Apache Security </h2>
<p>All your web files that need to be read by Apache should be readable by everyone as Apache itself is run under dhapache user. However, executable scripts like .php are executed under your own user and do not have to be world readable as they are not actually read by Apache, but executed via <a href="http://en.wikipedia.org/wiki/suEXEC" rel="nofollow" >suEXEC</a>. Quite the opposite - to prevent your code or database settings from being messed by any third-parties you SHOULD set permissions to these files explicitly to something like 640 or even 600 depending on who do you trust. </p>
<p><a name="Multiuser_security_setup_example"></a></p>
<h2>Multiuser security setup example </h2>
<p>For our example, we will create a <em>rainforce_www</em> user and a <em>aapp_www</em> group for serving web files with apache and setup a <em>rainforce</em> user with a 'aapp<em> group to manage mail and keep other files on DH privately. Since these records already exist, you will need to subsitute your own names.</em> </p>
<ul>
<li>Login to create the users <em>rainforce_www</em> and <em>rainforce</em> with shell access. </li>
<li>Create two groups - <em>aapp_www</em> and <em>aapp</em>. Note that users created in previous step are still members of the same default <em>pg</em>xxxxxx group. </li>
<li>Add <em>rainforce_www</em> to 'the 'aapp_www<em> group and </em>rainforce<em> to both the </em>aapp_www<em> and </em>aapp<em> groups</em> </li>
<li>Move your domain to <em>rainforce_www</em> account (mine is rainforce.org) </li>
<li>Now login to SSH with your <em>rainforce_www</em> user and change the default group for your home directory with "sgid" bit set to make all current and new files/directories created in this directory have the same <em>aapp_www</em> group. </li>
</ul>
<pre> $ chgrp -R aapp_www .
 $ chmod 2751 .
 $ chmod 2771 rainforce.org</pre>
<p>By setting 2771 the directory will be writable by the owner, the group and will be only executable by others. The contents of an executable only directory cannot be listed, but the files inside it can be read (if the permissions of the file allow it). It is important that the directory can be executable in order to allow static content (e.g. .html files) inside it to be read. Remember that directories you don't want anyone to have web access to, should be 0770 (writable by the owner and group, or 0750 writable by the owner and readable by group). Such strict permissions should by applied to password files, php include files or databases files (such as SQLite, BDB, etc). </p>
<ul>
<li>Do the same for <em>rainforce</em> user, but specify <em>aapp</em> group instead. </li>
</ul>
<pre>
 $ chgrp -R aapp .
 $ chmod 2751 .</pre>
<ul>
<li>Optionally modify umask in .bash_profile in user's home to 007 to make all files created by this user have 660 permissions set by default. If you want that newly created files by accessible by the web, you need to manually setup it's permissions to 664. </li>
</ul>
<p>Now I can login as the user "rainforce" and update the web-site in the ../rainforce_www/rainforce.org directory. There is one more setup needed. Because files copied from other accounts can have 644 permissions set instead of 664, you need a script which will update permissions to 664 or 660 to allow other group members modify such files. </p>
<h2><a name="SSH_key_fingerprints"></a>SSH key fingerprints </h2>
<p>Just gen your own I guess </p>
<h2>External Links </h2>
<ul>
<li><a href="http://oldfield.wattle.id.au/luv/permissions.html" title="http://oldfield.wattle.id.au/luv/permissions.html" rel="nofollow">Introduction to Unix file permissions</a> </li>
<li><a href="http://www.perlfect.com/articles/chmod.shtml" title="http://www.perlfect.com/articles/chmod.shtml" rel="nofollow">Understanding UNIX permission and chmod</a> </li>
</ul>
<p>Original Article from <a href="http://wiki.dreamhost.com/index.php?title=Security" rel="nofollow" >DreamHost Wiki</a></p>
<p>Content is available under <a href="http://www.gnu.org/copyleft/fdl.html" class="external " title="http://www.gnu.org/copyleft/fdl.html" rel="nofollow">GNU Free Documentation License 1.2</a>.</p>
<h2>Example File Permission Bits</h2>
<h3><code>/usr/lib/w3m/cgi-bin/dirlist.cgi</code></h3>
<pre>sub utype {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;PIPE&#039;,
    0020000, &#039;CHR&#039;,
    0040000, &#039;DIR&#039;,
    0060000, &#039;BLK&#039;,
    0100000, &#039;FILE&#039;,
    0120000, &#039;LINK&#039;,
    0140000, &#039;SOCK&#039;,
  );
  return $T{($_ &amp; 0170000)} || &#039;FILE&#039;;
}
&nbsp;
sub umode {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;p&#039;,
    0020000, &#039;c&#039;,
    0040000, &#039;d&#039;,
    0060000, &#039;b&#039;,
    0100000, &#039;-&#039;,
    0120000, &#039;l&#039;,
    0140000, &#039;s&#039;,
  );
&nbsp;
  return ($T{($_ &amp; 0170000)} || &#039;-&#039;)
     . (($_ &amp; 00400) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00200) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 04000) ? &#039;s&#039; :
       (($_ &amp; 00100) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00040) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00020) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 02000) ? &#039;s&#039; :
       (($_ &amp; 00010) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00004) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00002) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 01000) ? &#039;t&#039; :
       (($_ &amp; 00001) ? &#039;x&#039; : &#039;-&#039;));
}</pre>
<h3><code>/usr/lib/perl/5.8.4/linux/stat.ph</code></h3>
<pre>        eval &#039;sub S_IFMT () {00170000;}&#039; unless defined(&amp;S_IFMT);
        eval &#039;sub S_IFSOCK () {0140000;}&#039; unless defined(&amp;S_IFSOCK);
        eval &#039;sub S_IFLNK () {0120000;}&#039; unless defined(&amp;S_IFLNK);
        eval &#039;sub S_IFREG () {0100000;}&#039; unless defined(&amp;S_IFREG);
        eval &#039;sub S_IFBLK () {0060000;}&#039; unless defined(&amp;S_IFBLK);
        eval &#039;sub S_IFDIR () {0040000;}&#039; unless defined(&amp;S_IFDIR);
        eval &#039;sub S_IFCHR () {0020000;}&#039; unless defined(&amp;S_IFCHR);
        eval &#039;sub S_IFIFO () {0010000;}&#039; unless defined(&amp;S_IFIFO);
        eval &#039;sub S_ISUID () {0004000;}&#039; unless defined(&amp;S_ISUID);
        eval &#039;sub S_ISGID () {0002000;}&#039; unless defined(&amp;S_ISGID);
        eval &#039;sub S_ISVTX () {0001000;}&#039; unless defined(&amp;S_ISVTX);
        eval &#039;sub S_ISLNK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFLNK));
        }&#039; unless defined(&amp;S_ISLNK);
        eval &#039;sub S_ISREG {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFREG));
        }&#039; unless defined(&amp;S_ISREG);
        eval &#039;sub S_ISDIR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFDIR));
        }&#039; unless defined(&amp;S_ISDIR);
        eval &#039;sub S_ISCHR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFCHR));
        }&#039; unless defined(&amp;S_ISCHR);
        eval &#039;sub S_ISBLK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFBLK));
        }&#039; unless defined(&amp;S_ISBLK);
        eval &#039;sub S_ISFIFO {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFIFO));
        }&#039; unless defined(&amp;S_ISFIFO);
        eval &#039;sub S_ISSOCK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFSOCK));
        }&#039; unless defined(&amp;S_ISSOCK);
        eval &#039;sub S_IRWXU () {00700;}&#039; unless defined(&amp;S_IRWXU);
        eval &#039;sub S_IRUSR () {00400;}&#039; unless defined(&amp;S_IRUSR);
        eval &#039;sub S_IWUSR () {00200;}&#039; unless defined(&amp;S_IWUSR);
        eval &#039;sub S_IXUSR () {00100;}&#039; unless defined(&amp;S_IXUSR);
        eval &#039;sub S_IRWXG () {00070;}&#039; unless defined(&amp;S_IRWXG);
        eval &#039;sub S_IRGRP () {00040;}&#039; unless defined(&amp;S_IRGRP);
        eval &#039;sub S_IWGRP () {00020;}&#039; unless defined(&amp;S_IWGRP);
        eval &#039;sub S_IXGRP () {00010;}&#039; unless defined(&amp;S_IXGRP);
        eval &#039;sub S_IRWXO () {00007;}&#039; unless defined(&amp;S_IRWXO);
        eval &#039;sub S_IROTH () {00004;}&#039; unless defined(&amp;S_IROTH);
        eval &#039;sub S_IWOTH () {00002;}&#039; unless defined(&amp;S_IWOTH);
        eval &#039;sub S_IXOTH () {00001;}&#039; unless defined(&amp;S_IXOTH);
    }
    if(defined(&amp;__KERNEL__)) {
        eval &#039;sub S_IRWXUGO () {( &amp;S_IRWXU| &amp;S_IRWXG| &amp;S_IRWXO);}&#039; unless defined(&amp;S_IRWXUGO);
        eval &#039;sub S_IALLUGO () {( &amp;S_ISUID| &amp;S_ISGID| &amp;S_ISVTX| &amp;S_IRWXUGO);}&#039; unless defined(&amp;S_IALLUGO);
        eval &#039;sub S_IRUGO () {( &amp;S_IRUSR| &amp;S_IRGRP| &amp;S_IROTH);}&#039; unless defined(&amp;S_IRUGO);
        eval &#039;sub S_IWUGO () {( &amp;S_IWUSR| &amp;S_IWGRP| &amp;S_IWOTH);}&#039; unless defined(&amp;S_IWUGO);
        eval &#039;sub S_IXUGO () {( &amp;S_IXUSR| &amp;S_IXGRP| &amp;S_IXOTH);}&#039; unless defined(&amp;S_IXUGO);
        require &#039;linux/types.ph&#039;;
        require &#039;linux/time.ph&#039;;
    }
&nbsp;</pre>
<p><a href="http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.8a2/src/mozilla-source-1.8a2.tar.bz2 " rel="nofollow" >Mozilla-Source 1.8a2</a></p>
<pre>/* notice that these valuse are octal. */
const PERM_IRWXU = 00700;  /* read, write, execute/search by owner */
const PERM_IRUSR = 00400;  /* read permission, owner */
const PERM_IWUSR = 00200;  /* write permission, owner */
const PERM_IXUSR = 00100;  /* execute/search permission, owner */
const PERM_IRWXG = 00070;  /* read, write, execute/search by group */
const PERM_IRGRP = 00040;  /* read permission, group */
const PERM_IWGRP = 00020;  /* write permission, group */
const PERM_IXGRP = 00010;  /* execute/search permission, group */
const PERM_IRWXO = 00007;  /* read, write, execute/search by others */
const PERM_IROTH = 00004;  /* read permission, others */
const PERM_IWOTH = 00002;  /* write permission, others */
const PERM_IXOTH = 00001;  /* execute/search permission, others */
&nbsp;
const MODE_RDONLY   = 0x01;
const MODE_WRONLY   = 0x02;
const MODE_RDWR     = 0x04;
const MODE_CREATE   = 0x08;
const MODE_APPEND   = 0x10;
const MODE_TRUNCATE = 0x20;
const MODE_SYNC     = 0x40;
const MODE_EXCL     = 0x80;</pre>
<h3><code>/usr/include/libpng12/png.h</code></h3>
<pre>/* Transform masks for the high-level interface */
#define PNG_TRANSFORM_IDENTITY       0x0000    /* read and write */
#define PNG_TRANSFORM_STRIP_16       0x0001    /* read only */
#define PNG_TRANSFORM_STRIP_ALPHA    0x0002    /* read only */
#define PNG_TRANSFORM_PACKING        0x0004    /* read and write */
#define PNG_TRANSFORM_PACKSWAP       0x0008    /* read and write */
#define PNG_TRANSFORM_EXPAND         0x0010    /* read only */
#define PNG_TRANSFORM_INVERT_MONO    0x0020    /* read and write */
#define PNG_TRANSFORM_SHIFT          0x0040    /* read and write */
#define PNG_TRANSFORM_BGR            0x0080    /* read and write */
#define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
#define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
#define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */
#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only */</pre>
<h3><code>/usr/lib/python2.4/stat.py</code></h3>
<pre># Extract bits from the mode
&nbsp;
def S_IMODE(mode):
    return mode &amp; 07777
&nbsp;
def S_IFMT(mode):
    return mode &amp; 0170000
&nbsp;
# Constants used as S_IFMT() for various file types
# (not all are implemented on all systems)
&nbsp;
S_IFDIR  = 0040000
S_IFCHR  = 0020000
S_IFBLK  = 0060000
S_IFREG  = 0100000
S_IFIFO  = 0010000
S_IFLNK  = 0120000
S_IFSOCK = 0140000
&nbsp;
# Functions to test for each file type
&nbsp;
def S_ISDIR(mode):
    return S_IFMT(mode) == S_IFDIR
&nbsp;
def S_ISCHR(mode):
    return S_IFMT(mode) == S_IFCHR
&nbsp;
def S_ISBLK(mode):
    return S_IFMT(mode) == S_IFBLK
&nbsp;
def S_ISREG(mode):
    return S_IFMT(mode) == S_IFREG
&nbsp;
def S_ISFIFO(mode):
    return S_IFMT(mode) == S_IFIFO
&nbsp;
def S_ISLNK(mode):
    return S_IFMT(mode) == S_IFLNK
&nbsp;
def S_ISSOCK(mode):
    return S_IFMT(mode) == S_IFSOCK
&nbsp;
# Names for permission bits
&nbsp;
S_ISUID = 04000
S_ISGID = 02000
S_ENFMT = S_ISGID
S_ISVTX = 01000
S_IREAD = 00400
S_IWRITE = 00200
S_IEXEC = 00100
S_IRWXU = 00700
S_IRUSR = 00400
S_IWUSR = 00200
S_IXUSR = 00100
S_IRWXG = 00070
S_IRGRP = 00040
S_IWGRP = 00020
S_IXGRP = 00010
S_IRWXO = 00007
S_IROTH = 00004
S_IWOTH = 00002
S_IXOTH = 00001</pre>
<h3><code>/usr/include/bits/stat.h</code></h3>
<pre>/* Encoding of the file mode.  */
&nbsp;
#define __S_IFMT        0170000 /* These bits determine file type.  */
&nbsp;
/* File types.  */
#define __S_IFDIR       0040000 /* Directory.  */
#define __S_IFCHR       0020000 /* Character device.  */
#define __S_IFBLK       0060000 /* Block device.  */
#define __S_IFREG       0100000 /* Regular file.  */
#define __S_IFIFO       0010000 /* FIFO.  */
#define __S_IFLNK       0120000 /* Symbolic link.  */
#define __S_IFSOCK      0140000 /* Socket.  */
&nbsp;
/* POSIX.1b objects.  Note that these macros always evaluate to zero.  But
   they do it by enforcing the correct use of the macros.  */
#define __S_TYPEISMQ(buf)  ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSEM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSHM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
&nbsp;
/* Protection bits.  */
&nbsp;
#define __S_ISUID       04000   /* Set user ID on execution.  */
#define __S_ISGID       02000   /* Set group ID on execution.  */
#define __S_ISVTX       01000   /* Save swapped text after use (sticky).  */
#define __S_IREAD       0400    /* Read by owner.  */
#define __S_IWRITE      0200    /* Write by owner.  */
#define __S_IEXEC       0100    /* Execute by owner.  */</pre>
<h3><code>/usr/include/linux/nfs.h</code></h3>
<pre>#define NFS_FIFO_DEV    (-1)
#define NFSMODE_FMT     0170000
#define NFSMODE_DIR     0040000
#define NFSMODE_CHR     0020000
#define NFSMODE_BLK     0060000
#define NFSMODE_REG     0100000
#define NFSMODE_LNK     0120000
#define NFSMODE_SOCK    0140000
#define NFSMODE_FIFO    0010000</pre>
<h3><code>/usr/include/linux/nfs3.h</code></h3>
<pre>#define NFS3_FIFO_DEV           (-1)
#define NFS3MODE_FMT            0170000
#define NFS3MODE_DIR            0040000
#define NFS3MODE_CHR            0020000
#define NFS3MODE_BLK            0060000
#define NFS3MODE_REG            0100000
#define NFS3MODE_LNK            0120000
#define NFS3MODE_SOCK           0140000
#define NFS3MODE_FIFO           0010000
&nbsp;
/* Flags for access() call */
#define NFS3_ACCESS_READ        0x0001
#define NFS3_ACCESS_LOOKUP      0x0002
#define NFS3_ACCESS_MODIFY      0x0004
#define NFS3_ACCESS_EXTEND      0x0008
#define NFS3_ACCESS_DELETE      0x0010
#define NFS3_ACCESS_EXECUTE     0x0020
#define NFS3_ACCESS_FULL        0x003f</pre>
<h3><code>/usr/include/linux/stat.h</code></h3>
<pre>#define S_IFMT  00170000
#define S_IFSOCK 0140000
#define S_IFLNK  0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000
&nbsp;
#define S_ISLNK(m)      (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m)      (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m)      (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m)      (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m)      (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)     (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)     (((m) &amp; S_IFMT) == S_IFSOCK)
&nbsp;
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
&nbsp;
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
&nbsp;
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001</pre>
<h2>Further File Permissions Reading</h2>
<h3>Related PHP Functions</h3>
<ul>
<li><a href="http://php.net/manual/en/function.fileperms.php" rel="nofollow" >fileperms</a></li>
<li><a href="http://php.net/manual/en/function.stat.php" rel="nofollow" >stat</a></li>
<li><a href="http://php.net/manual/en/function.chmod.php" rel="nofollow" >chmod</a></li>
<li><a href="http://php.net/manual/en/function.clearstatcache.php" rel="nofollow" >clearstatcache</a></li>
<li><a href="http://php.net/manual/en/function.chown.php" rel="nofollow" >chown</a></li>
<li><a href="http://php.net/manual/en/function.chgrp.php" rel="nofollow" >chgrp</a></li>
<li><a href="http://php.net/manual/en/function.lchown.php" rel="nofollow" >lchown</a></li>
<li><a href="http://php.net/manual/en/function.lchgrp.php" rel="nofollow" >lchgrp</a></li>
<li><a href="http://php.net/manual/en/function.touch.php" rel="nofollow" >touch</a></li>
<li><a href="http://php.net/manual/en/function.lstat.php" rel="nofollow" >lstat</a></li>
<li><a href="http://php.net/manual/en/function.fstat.php" rel="nofollow" >filestat</a></li>
<li><a href="http://php.net/manual/en/function.fileatime.php" rel="nofollow" >fileatime</a></li>
<li><a href="http://php.net/manual/en/function.filectime.php" rel="nofollow" >filectime</a></li>
<li><a href="http://php.net/manual/en/function.filegroup.php" rel="nofollow" >filegroup</a></li>
<li><a href="http://php.net/manual/en/function.fileinode.php" rel="nofollow" >fileinode</a></li>
<li><a href="http://php.net/manual/en/function.filemtime.php" rel="nofollow" >filemtime</a></li>
<li><a href="http://php.net/manual/en/function.fileowner.php" rel="nofollow" >fileowner</a></li>
<li><a href="http://php.net/manual/en/function.filesize.php" rel="nofollow" >filesize</a></li>
<li><a href="http://php.net/manual/en/function.filetype.php" rel="nofollow" >filetype</a></li>
<li><a href="http://php.net/manual/en/function.is-writable.php" rel="nofollow" >is_writable</a></li>
<li><a href="http://php.net/manual/en/function.is-readable.php" rel="nofollow" >is_readable</a></li>
<li><a href="http://php.net/manual/en/function.is-executable.php" rel="nofollow" >is_executable</a></li>
<li><a href="http://php.net/manual/en/function.is-file.php" rel="nofollow" >is_file</a></li>
<li><a href="http://php.net/manual/en/function.is-dir.php" rel="nofollow" >is_dir</a></li>
<li><a href="http://php.net/manual/en/function.is-link.php" rel="nofollow" >is_link</a></li>
<li><a href="http://php.net/manual/en/function.file-exists.php" rel="nofollow" >file_exists</a></li>
<li><a href="http://php.net/manual/en/function.disk-total-space.php" rel="nofollow" >disk_total_space</a></li>
<li><a href="http://php.net/manual/en/function.disk-free-space.php" rel="nofollow" >disk_free_space</a></li>
</ul>
<h3>Special file types</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#link-invocation" rel="nofollow" >link invocation</a>:  Make a hard link via the link syscall</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#ln-invocation" rel="nofollow" >ln invocation</a>: Make links between files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkdir-invocation" rel="nofollow" >mkdir invocation</a>: Make directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkfifo-invocation" rel="nofollow" >mkfifo invocation</a>: Make FIFOs (named pipes)</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mknod-invocation" rel="nofollow" >mknod invocation</a>: Make block or character special files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#readlink-invocation" rel="nofollow" >readlink invocation</a>: Print the referent of a symbolic link</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#rmdir-invocation" rel="nofollow" >rmdir invocation</a>: Remove empty directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#unlink-invocation" rel="nofollow" >unlink invocation</a>: Remove files via unlink syscall</li>
</ul>
<h3>Changing file attributes</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chown-invocation" rel="nofollow" >chown invocation</a>: Change file owner and group</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chgrp-invocation" rel="nofollow" >chgrp invocation</a>: Change group ownership</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chmod-invocation" rel="nofollow" >chmod invocation</a>: Change access permissions</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#touch-invocation" rel="nofollow" >touch invocation</a>: Change file timestamps</li>
</ul>
<p><a href="http://www.askapache.com/security/chmod-stat.html"></a><a href="http://www.askapache.com/security/chmod-stat.html">Chmod, Umask, Stat, Fileperms, and File Permissions</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/chmod-stat.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SEO Secrets of AskApache Part 2</title>
		<link>http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html</link>
		<comments>http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html#comments</comments>
		<pubDate>Fri, 17 Oct 2008 21:44:22 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Making Money]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[htaccess tutorial]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Pagerank]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[seo secrets]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=567</guid>
		<description><![CDATA[<p><a rel="lb" class="IFL hs hs31" href='http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html' title="Advanced SEO part 2: Search Engine Indexing and Pagerank Control"></a>This is part II of the <a href="http://www.askapache.com/seo/seo-secrets.html">Advanced SEO used on AskApache.com Series</a> and describes how to control which urls are indexed by Search Engines and how to move them higher up in Search Results.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.askapache.com/seo/seo-secrets.html">part I: SEO Secrets of AskApache.com</a> we talked about content and building a website to be your &#8220;SEO Base&#8221;.  This article discusses some advanced SEO concepts to get a site indexed, move your best pages higher in search results, and controlling the pagerank/seo-juice of your site.  but relatively easy ways to control and tweak WHAT urls on your site are indexed, and HOW.  I&#8217;ve heard some people refer to this as &#8220;controlling pagerank flow&#8221; and &#8220;controlling pagerank juice&#8221;, basically we want our best pages to rank higher in the search engine results.</p>
<p><strong>Big Picture:</strong> Going from no website to AskApache.com in less than a year can be accomplished by anyone with unique content and a resolve to avoid any shortcuts and take it one step at a time.</p>
<p class="cnote">We want what Google wants, to provide the most relevant content for someone who is doing a search.   Basically, you want every url on your site that has unique content to be included in the index.  In other words, <strong>you have to think like a search engine</strong>!</p>
<hr class="C" />
<h2>The Goal of Google</h2>
<p>Here&#8217;s what I mean, Google approaches search with the overwhelming goal of bringing the content to a searcher that is the most-likely to be what that searcher is searching for.  Another way of looking at it is something I read on Google&#8230;</p>
<blockquote cite="http://www.google.com/"><p>Google&#8217;s goal is to get you off of their site as fast as possible by providing you with exactly what you are looking for.</p></blockquote>
<hr class="C" />
<h2>Think about SEO like this</h2>
<p>If you search for <a href="http://www.google.com/search?aq=f&#038;complete=1&#038;hl=en&#038;q=htaccess+tutorial+for+seo&#038;btnG=Search" rel="nofollow"  title="Google Search for htaccess tutorial for seo">htaccess tutorial for seo</a> on Google, would you be more likely to visit a <strong>tutorial about using .htaccess for seo</strong> or <strong>a category page for htaccess articles</strong>?  AskApache.com has both of those urls included in the index, but the article ranks higher than the category page, as it very well should.</p>
<hr class="C" />
<h2>Get Your URLS Indexed</h2>
<p>Before I explain how I am able to help Google and other search engines rank my article pages higher than my category pages, we need to get the urls in the index or nothing will show up.  There are many well-discussed methods for getting included in the index, so I&#8217;ll just list a few that I use.</p>
<ol>
<li>Provide High-Quality original content, people will link to it</li>
<li>Get a sitemap and use <a href="https://www.google.com/webmasters/tools/siteoverview?hl=en" rel="nofollow" >Google Webmaster Tools</a></li>
<li>Publish an <a href="http://feeds.askapache.com/apache/htaccess" rel="nofollow" >RSS/Atom Feed</a> and ping the net when you publish a post</li>
<li>Use robots.txt and robots meta tags</li>
</ol>
<h3>Your URLs in the index</h3>
<p>Here&#8217;s how to find out which of your pages are indexed.</p>
<ul>
<li>Indexed pages in your site: <a href="http://www.google.com/search?q=site:www.askapache.com" rel="nofollow" >site:</a></li>
<li>Pages that link to your site&#8217;s front page: <a href="http://www.google.com/search?q=link:www.askapache.com" rel="nofollow" >link:</a></li>
<li>The current cache of your site: <a href="http://www.google.com/search?q=cache:www.askapache.com" rel="nofollow" >cache:</a></li>
<li>Information about your site: <a href="http://www.google.com/search?q=info:www.askapache.com" rel="nofollow" >info:</a></li>
<li>Pages that are similar to your site: <a href="http://www.google.com/search?q=related:www.askapache.com" rel="nofollow" >related:</a></li>
</ul>
<hr class="C" />
<h2>Break It Down</h2>
<p>Yo homeslice! I didn&#8217;t mean break dance..  I mean lets simplify AskApache in the context of getting our urls indexed high/low.  Here&#8217;s the stats:  <strong>1 Homepage, 206 Articles, 19 Pages, 31 Categories</strong></p>
<h3>1 Homepage</h3>
<p>This page is generally the highest ranking page in the index, it should contain links to your best urls, and provide easy navigation</p>
<h3>206 Specific Topic Articles</h3>
<p>These are the article&#8217;s (like this one) of AskApache.com and are the main source of search engine traffic.  You want each url (if its a good article) to be ranked as high as possible.  Some keys are to really make each article specific to a topic by using best-practice (X)HTML.</p>
<h3>19 Static Pages</h3>
<p>Most of these are pages like the online-tools hosted on this site, or other basic pages like about, contact us, site-map, etc..  Some of these you may want to rank very high ( like the /about/ page ) and some you may not want to even be included in the index.</p>
<h3>31 Specific Topic Category Pages</h3>
<p>These are tricky because they are generally just lists of articles from each category, which isn&#8217;t specific enough to get much seach-engine-traffic, but is very useful to site visitors.  I beefed up my category pages by adding additional information about the category topic in addition to excerpts of the articles.</p>
<hr class="C" />
<h2>Higher Pagerank = Higher Up in Search Results</h2>
<p>So Googlebot and other search engine robots have these crazy complicated algorithms (many patented) that SEO Industry types may get caught up in and try to technically analyze them.  I&#8217;m sure you&#8217;ve seen/read/heard the complicated advice that will always be pushed by many&#8230; advice like:</p>
<ul>
<li>analyze the number of words in the description/title/1st paragraph/etc.</li>
<li>Make sure your &#8220;keyword&#8221; is sprinkled throughout the text every 10-30th word..</li>
<li>Other equally unexciting technical analysis</li>
</ul>
<p>Now if you&#8217;ve had success with that then props to you, success is success, but I personally choose to completely ignore all that.  The number 1 thing that the top search engines advise is to design your page for a <strong>Human Visitor</strong>, not a computer.  The golden rule for me is how I would rank the page, not how some algorithm would.</p>
<hr class="C" />
<h2>Designing for a Human Visitor</h2>
<p>This is a major factor in your site being at the top vs. nowhere.   You design your HTML to be as minimal as possible (see source code for my homepage) and contain ONLY the neccessary elements.  Above all, use semantically sound XHTML markup.  (view source of <a href="http://www.w3.org/" rel="nofollow"  title="World Wide Web Consortium"><acronym title="World Wide Web Consortium">W3C</acronym></a>)</p>
<h3>External CSS/Javascript</h3>
<p>Get your javascript and CSS out of your HTML and use external files (like this site) ALWAYS!  You should start with just the HTML, no css, no colors, no javascript, and THEN you add the .css and then you add the javascript.</p>
<h3>Site Accessibility</h3>
<p>Say your browser didn&#8217;t have a mouse, didn&#8217;t support images, css, javascript, or even colors!  Your HTML should be structured such that your page is still easily readable and easy to navigate.  You can use lynx, links, and many other terminal-based browsers to test for this&#8230; please see the <a href="http://www.w3.org/WAI/" rel="nofollow" >Web Accessibility Initiative (<acronym title="Web Accessibility Initiative">WAI</acronym>)</a> for detailed info.</p>
<blockquote cite="http://en.wikipedia.org/wiki/Web_accessibility"><p><a href="http://en.wikipedia.org/wiki/Web_accessibility" rel="nofollow" >Web accessibility</a> refers to the practice of making websites usable by people of all abilities and disabilities. When sites are correctly designed, developed and edited, all users can have equal access to information and functionality. For example, when a site is coded with semantically meaningful HTML, with textual equivalents provided for images and with links named meaningfully, this helps blind users using text-to-speech software and/or text-to-Braille hardware.</p>
</blockquote>
<hr class="C" />
<h2>Controlling a URL&#8217;s Pagerank</h2>
<p>A few tools and techniques are available for controlling the &#8220;juice&#8221; or &#8220;pagerank&#8221; of your urls.</p>
<ol>
<li>Robots.txt</li>
<li>Robots Meta Tags</li>
<li>Links</li>
</ol>
<h2>Robots.txt</h2>
<p>I&#8217;ve done quite a bit of research and experimentation with <a href="http://www.askapache.com/search/robots.txt">robots.txt files</a>, which is a file located in the root of your website at <a href="http://www.askapache.com/robots.txt">http://www.askapache.com/robots.txt</a> that is downloaded by all legitimate search engine spiders/bots and used as a Blacklist to prevent certain urls from being indexed.  Here are a few of the articles on this site, which you may skip if you like as they don&#8217;t illustrate the big-picture that I am going to discuss now.</p>
<ul>
<li><a href="http://www.askapache.com/seo/robotstxt-mattcutts-noindex.html">Control Flow of Pagerank with robots.txt and NoFollow, NoIndex</a></li>
<li><a href="http://www.askapache.com/seo/updated-robotstxt-for-wordpress.html">WordPress robots.txt</a></li>
<li><a href="http://www.askapache.com/seo/seo-with-robotstxt.html">SEO with Robots.txt</a></li>
<li><a href="http://www.askapache.com/google/adsense-robots.html">Google AdSense using robots.txt</a></li>
<li><a href="http://www.askapache.com/seo/wordpress-robotstxt-seo.html">WordPress robots.txt file optimized for SEO and Google</a></li>
</ul>
<h3>How To Use Robots.txt</h3>
<p>Even though robots.txt files are for whitelisting and blacklisting urls, I have found that they should only be used as an extreme form of blacklisting.  When you Disallow a url in your robots.txt file, that means most search engine bots won&#8217;t even LOOK at the url.  As you can see in the below example, I only disallow urls that shouldn&#8217;t ever be LOOKED at.  The real powertool is the <strong>robots meta tag</strong>.</p>
<pre>User-agent: *
Disallow: /cgi-bin
Disallow: /wp-admin
Disallow: /wp-includes
Disallow: /wp-content
&nbsp;
Sitemap: http://www.askapache.com/sitemap.xml</pre>
<hr class="C" />
<h2>Robots Meta Tag</h2>
<p>Ok I&#8217;m really trying to simplify, because what you should understand is the big-picture.  Every page can have a robots meta tag in the header, and this robots meta tag can tell the search-engine to index/not-index AND follow/not-follow.  Here are some examples:</p>
<pre>&lt;meta name=&quot;robots&quot; content=&quot;index&quot; /&gt;
&lt;meta name=&quot;robots&quot; content=&quot;noindex&quot; /&gt;
&lt;meta name=&quot;robots&quot; content=&quot;noindex,follow&quot; /&gt;
&lt;meta name=&quot;robots&quot; content=&quot;index,nofollow&quot; /&gt;</pre>
<h3>content=&#8221;index&#8221; / noindex</h3>
<p><code>index</code> means the search engine is free to index, archive, cache, and follow the page whereas <code>noindex</code> means DO NOT include this page in the search engine results.</p>
<h3>content=&#8221;follow&#8221; / nofollow</h3>
<p><code>follow</code> means the search engine is free to LOOK at the page and follow the links on the page whereas <code>nofollow</code> means DO NOT follow the links on the page.</p>
<hr class="C" />
<h3>WordPress Auto-Robots meta tag code</h3>
<p>Just add this to any plugin file and it will add the right robots meta tag to your site..  tweak to taste.</p>
<pre>function askapache_robots_header(){
 global $wpdb;
&nbsp;
 $robot = &#039;&lt;meta name=&quot;robots&quot; content=&quot;noindex,follow,nocache,noarchive&quot; /&gt;&#039;;

 if ( is_paged() || is_search() || is_404() || is_author() || is_tag() )
   $robot = &#039;&lt;meta name=&quot;robots&quot; content=&quot;noindex,follow&quot; /&gt;&#039;;
 elseif ( is_home() || is_front_page() || is_single() )
   $robot = &#039;&lt;meta name=&quot;robots&quot; content=&quot;follow,index&quot; /&gt;&#039;;
 elseif ( is_category() || is_page() )
   $robot = &#039;&lt;meta name=&quot;robots&quot; content=&quot;follow&quot; /&gt;&#039;;
&nbsp;
 echo $robot . &quot;\n&quot;;
}
add_action( &#039;wp_head&#039;, &#039;askapache_robots_header&#039; );</pre>
<hr class="C" />
<h2>Links</h2>
<p>External and Internal Links are the crux of SEO.  It&#8217;s important to start FIRST on your Internal Links and linking structure&#8230; Once you are satisfied that the correct pages are indexed and ranked appropriately, then you can begin to look at external links.</p>
<ul>
<li>The fewer links on a page, generally the better.</li>
<li>If every page of your site points to the same url on your site, pagerank goes up from the number of internal links.</li>
<li>Use of the <code>rel</code>, <code>title</code>, <code>alt</code> attribute semantically is very helpful.  (next, prev, index)</li>
<li>Put your best links higher up in the XHTML, and put helpful/solid links at the end.</li>
<li>You can add <code>rel="nofollow"</code> to links that you dont want followed.</li>
</ul>
<p>The web has gotten to be so full of malicious/non-helpful SEO activity that I recommend developing your content NOT external links.  If you want to do this right and provide great content that makes search engine users happy and makes the web better, then explore this blog and develop content until the next article in this series, where I&#8217;ll show you how to <strong>make your site explode</strong>.</p>
<p class="anote">Stay tuned for Part III, which will dive deeper into the pipeworks of AskApache.com</p>
<p><a href="http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html"></a><a href="http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html">SEO Secrets of AskApache Part 2</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Elite Log File Scrolling with Color Syntax</title>
		<link>http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html</link>
		<comments>http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html#comments</comments>
		<pubDate>Sat, 09 Aug 2008 04:56:10 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CCZE]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Elite]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[fifo]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Renice]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell History]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1067</guid>
		<description><![CDATA[<p><a class="IFR hs hs07" href="http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html" title="Colored Server Log Scrolling"></a>Scrolls the latest log entries for multiple log files to the current screen or to any other monitor or TTY <strong>in color using syntax highlighting</strong>, making debugging easier and saving a lot of time for multi-monitor workstations.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://uploads.askapache.com/2008/08/colored-logs2.png" rel="nofollow" class="IFR" rel="lb" ><img src="http://uploads.askapache.com/2008/08/colored-logs2.png" alt="Scroll Logs on Alternate Monitor for Server Debugging" title="colored-logs2" width="350" height="143" /></a>Ok peeps, one of the coolest hacks yet.  If you have multiple PC&#8217;s/Monitors at your workstation like I do, it can be helpful to display various information on one screen while you work on another.<br class="C" /></p>
<p>This article shows how I <strong>continuously scroll the logs</strong> for a server/site I am working on, thus saving me a lot of time by providing <em>real-time debugging</em> on a separate screen.  Not only does this scroll the latest log entries as they are created, it <strong>displays them in color using syntax highlighting</strong> to make your logs incredibly easy to understand and parse.</p>
<h2>Example Output</h2>
<p>The thing to realize is that this output is continuously scrolling on your monitor, and using some cool linux shell tricks you can make it output at a certain speed and show a certain number of lines.  Another cool feature is you can display multiple files at the same time, and the filename will be output for each file above the log output.</p>
<p><a href="http://uploads.askapache.com/2008/08/colored-logs1.png" rel="nofollow" rel="lb" ><img src="http://uploads.askapache.com/2008/08/colored-logs.png" alt="Colored Apache Server Logs Scrolling Display" title="Colored Server Log Scrolling" width="640" height="570" /></a></p>
<h2>What Logs</h2>
<p>I&#8217;ve explained in various articles on this site how to create and use various custom log files using .htaccess files and other tricks for non-root users. I use shared hosting all the time too you know&#8230;  Here are some log files you can generally use if you can use .htaccess files <em>(if you can control .htaccess you can control a binary php-cgi, which could be a shell script thats execs the php binary of your choice with your own environment variables, which is a workaround to getting a custom php.ini, which is how you specify a php error log)</em>.</p>
<ul>
<li>php error log</li>
<li>mod_security audit log</li>
<li>mod_security debug log</li>
<li>apache error log</li>
<li>apache access log</li>
</ul>
<p>Any log file can be used with this method, actually ANY file containing text can be used with this method, even fifo pipes as we will see in a bit ;)</p>
<h2>Installation</h2>
<h3>PCRE</h3>
<p>First you need <a href="http://www.pcre.org/" rel="nofollow" >PCRE</a> &#8211; Perl Compatible Regular Expressions, which you can download <a href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/" rel="nofollow" >here</a>.  Note that I had to install <a href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-6.7.tar.gz" rel="nofollow" >pcre version 6.7</a> to get it to work with ccze.</p>
<h3>CCZE</h3>
<p>Now you need <a href="http://freshmeat.net/projects/ccze/" rel="nofollow" >CCZE</a>, which colorizes and outputs (emulating tail) the log files.</p>
<blockquote><p>CCZE is a robust and modular log colorizer with plugins for apm, exim, fetchmail, httpd, postfix, procmail, squid, syslog, ulogd, vsftpd, xferlog, and more.</p>
</blockquote>
<h2>Post-Install Setup</h2>
<p>Ok so once you&#8217;ve installed ccze you can start using it right away, or you can continue reading to see how I&#8217;ve set it up for readable scrolling.  If the following setup isn&#8217;t to your taste, you can always just use <a href="http://www.teaser.fr/~amajorel/wtail/wtail-0.2.2.tar.gz" rel="nofollow" >wtail</a>, a colorless multi-file scroller that uses separate scrolling windows in your terminal similar to the screen program.</p>
<h3>Create Logs Folder</h3>
<p>First I created a folder called <code>/logs/</code> for my site, then for all subsequent commands chdir to it.</p>
<pre class='prebash'>$ mkdir /home/site.com/logs
$ cd /home/site.com/logs</pre>
<h3>Create Symlinks to Logs</h3>
<p>In the new logs folder I created soft symlinks to all the various log files, not neccessary but makes everything much easier and organized.</p>
<pre class='prebash'>$ ln -s /actual/logs/site.com/http/access.log access.log
$ ln -s /actual/logs/site.com/http/error.log error.log
$ ln -s /home/site.com/php_error.log php_error.log
$ ln -s /home/site.com/modsec_audit.log modsec_audit.log
$ ln -s /home/site.com/modsec_debug.log modsec_debug.log</pre>
<h3>Make a fifo Pipe</h3>
<p>FIFO stands for first-in-first-out and is a somewhat complex feature of linux/bsd/unix shells that let you send data into it and read the data that comes out of it, just like a pipe.</p>
<pre class='prebash'>$ mkfifo pipe</pre>
<h2>Scrolling the Logs</h2>
<p><strong>First</strong> cd to the log directory you created.</p>
<pre class='prebash'>$ cd /home/site.com/logs</pre>
<p>Now we will use the tail program to output 120 lines of each of these log files every half of a second, only displaying changes/new log entries.  We send that output into the fifo pipe we created using shell redirection and then instruct the command to run in the background using the ampersand to access built-in <em>(bash/sh)</em> job control.</p>
<pre class='prebash'>$ tail -s .5 -n 120 -f access.log php_error.log error.log modsec_audit.log &gt;pipe &amp;</pre>
<h3>Displaying the Colorized Scrolling Output</h3>
<p>So every .5 seconds the tail command outputs any new log entries from those files into the fifo pipe, so now we need to use the ccze program to use the fifo pipe as its input log file.  Normally you run ccze like the cat command and it just outputs the input colorized, by using tail and a fifo pipe we are able to make this awesome trick work.</p>
<h4>To current TTY</h4>
<pre class='prebash'>$ ccze &lt;pipe</pre>
<h4>To any TTY</h4>
<pre class='prebash'>$ ccze &lt; pipe &gt;/dev/pts/2 &amp;</pre>
<h3>Save All Colored Output</h3>
<p>This appends the colorized output to the file in the CWD, super.log</p>
<pre class='prebash'>$ ccze -A &lt;pipe | tee -a super.log</pre>
<h3>Kill the Scrolling</h3>
<p>Immediately kills any processes used by tail and ccze.</p>
<pre class='prebash'>$ pkill -9 ccze\|tail</pre>
<h2>Going Further. Hackers only.</h2>
<p>Here are some other examples of using ccze with fifo pipes, more as an excercise than anything practical as most lines don&#8217;t work, I just grabbed them from my shell history file.</p>
<pre class='prebash'>tail -f access.log &gt;pipe &amp; ccze &lt;pipe | tee -a super.log &gt;/dev/pts/2
tail -f access.log &gt;pipe &amp; ccze &lt;pipe | tee -a super.log &gt;/dev/pts/2 &amp;
&nbsp;
exec 3&lt;&gt; pipe; while ccze &gt;/dev/pts/2 &lt;&amp;3; do tail -f access.log &gt;pipe; done; exec 3&gt;&amp;-
exec 3&lt;&gt; pipe; ccze &lt;&amp;3 &gt;/dev/pts/2 &amp; ; tail -f access.log &gt;pipe; exec 3&gt;&amp;-
exec 3&lt;&gt; pipe; ccze &lt;&amp;3 &gt;/dev/pts/2 &amp; ; tail -f access.log &gt;pipe
exec 3&lt;&gt; pipe; ccze &lt;&amp;3 &gt;/dev/pts/2 &amp; tail -f access.log &gt;pipe
ccze &lt;&amp;3 &gt;/dev/pts/2 &amp;
ccze 0&lt;&amp;3 |tee -a super.log &gt; /dev/pts/2 &amp;
ccze &lt;&amp;3 |tee -a super.log &gt; /dev/pts/2 &amp;
ccze &lt;pipe |tee -a /dev/pts/2 &amp; tail -s .5 -n 120 -f php_error.log error.log modsec_audit.log &gt;pipe &amp;
ccze | tee -a /dev/pts/2 &lt;pipe
&nbsp;
ccze &lt; tee -a /dev/pts/2 pipe &gt;/dev/pts/2
ccze &lt;|tee -a /dev/pts/2 pipe &gt;/dev/pts/2
ccze &lt;tee -a /dev/pts/2 &lt;pipe
ccze &lt;pipe &gt;&gt; tee -a super.log &gt;/dev/pts/2
cat &lt;pipe | ccze
ccze &lt;pipe &gt;&gt;/dev/pts/2 &amp;
&nbsp;
tail -fq access.log | ccze  &amp;&gt;/dev/pts/1
tail -qf access.log |ccze &amp;&gt;/dev/pts/1 &amp;
tail -f access.log | ccze &gt; $SSH_TTY
&nbsp;
( ccze &gt; /dev/pts/2 )&lt;pipe
( ccze &gt; /dev/pts/2 )&lt;pipe
( ccze &gt; /dev/pts/2 )&lt;pipe &amp; tail -f access.log | pipe
( ccze &gt; /dev/pts/2 )&lt;pipe &amp; tail -f access.log | ./pipe
&nbsp;
ccze &lt;pipe &gt; /dev/pts/2 &amp; tail -f access.log &gt;pipe
ccze  &lt;pipe&gt; /dev/pts/2 &amp; tail -f access.log &gt;pipe
ccze  &lt; pipe &gt; /dev/pts/2 &amp; tail -f access.log &gt;pipe
ccze &lt; pipe &gt;/dev/pts/2 &amp; tail -f access.log &gt;pipe
ccze &lt; pipe &gt;/dev/pts/2 &amp; tail -f access.log &gt;pipe &amp;
ccze &lt; pipe &gt;/dev/pts/2 &amp; tail -n 40 -s 2 -f error.log modsec_audit.log php_error.log  &gt;pipe &amp;
ccze &lt; pipe &gt;| tee -a super.log | &gt;/dev/pts/2 &amp; tail -n 80 -s 1 -f error.log modsec_audit.log php_error.log  &gt;pipe &amp;
ccze &lt; pipe &gt;/dev/pts/2 &amp; tail -n 100 -s 1 -f error.log modsec_audit.log php_error.log &gt;pipe &amp;
ccze &lt; pipe &gt;/dev/pts/2 &amp; tail -n 100 -s 1 -f error.log modsec_audit.log php_error.log &gt;pipe &amp;
&nbsp;
tail -f access.log | ccze &gt; pipe &amp; /dev/pts/2/&lt;pipe
tail -f access.log | ccze &gt; pipe &amp; /dev/pts/2&lt;pipe
&nbsp;
ccze &lt; $(tail -n 20 -s 1 -f access.log)
ccze &lt; | $(tail -n 20 -s 1 -f access.log)
ccze &lt; |$(tail -n 20 -s 1 -f access.log)</pre>
<h3>Shell Script</h3>
<p>I also hacked together a little shell script that you may wish to hack to your needs.  Its actually pretty sweet if you can figure it out.</p>
<pre class='prebash'>#!/bin/bash -l
set -o xtrace
renice -p $$ 15
&nbsp;
pkill -9 tee\|ccze &amp;&gt;/dev/null || echo -n
disown -a &amp;&gt;/dev/null || echo
&nbsp;
[[ -r &quot;~/pipe&quot; ]] &amp;&amp; rm -rf ~/pipe
&nbsp;
mkfifo ~/pipe
&nbsp;
cd /home/askapache.com/logs
&nbsp;
[[ -r &quot;superlog.log&quot; ]] &amp;&amp; echo &quot;Found old logfile, moving.&quot; &amp;&amp; mv superlog.log `command ls|wc -l`-superlog.log
&nbsp;
ccze &lt;$HOME/pipe &gt; $SSH_TTY &amp; tail -n 150 -s .5 -f  php_error.log error.log modsec_audit.log &gt;$HOME/pipe &amp;
disown %2; &amp;&amp; disown %3;
&nbsp;
disown -a
&nbsp;
sleep 60 &amp;
disown $! || disown %1
&nbsp;
for i in `seq 1 4`;do echo -n $&#039;\a&#039;; sleep 1;done
kill -9 $J1
kill -9 $J2
&nbsp;
logout
exit 0</pre>
<p><a href="http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html"></a><a href="http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html">Elite Log File Scrolling with Color Syntax</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fsockopen Power Plays</title>
		<link>http://www.askapache.com/php/fsockopen-socket.html</link>
		<comments>http://www.askapache.com/php/fsockopen-socket.html#comments</comments>
		<pubDate>Wed, 02 Jul 2008 11:42:56 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Cache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[AskApache Crazy Cache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[Blocking]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[Fsockopen]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pipelining]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Snoopy]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1046</guid>
		<description><![CDATA[<p><a class="IFL hs hs17" rel="lb" href='http://www.askapache.com/php/fsockopen-socket.html' title="Fsockopen Power"></a><strong>PHP's <a href="http://php.net/manual/en/function.fsockopen.php">fsockopen</a> function lets you open an Internet or Unix domain socket connection for connecting to a resource, and is one of the most powerful functions available in the php language.</strong><br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://php.net/manual/en/function.fsockopen.php" rel="nofollow" class="IFL hs hs17" rel="lb" href='http://uploads.askapache.com/2008/07/fsockopen-lightning.jpg' title="Fsockopen Power"></a><strong>PHP&#8217;s function <a >fsockopen</a> lets you open an Internet or Unix domain socket connection for connecting to a resource, and is one of the most powerful functions.</strong>  fsockopen could be described as creating a direct link to the wire connected to a resource, which means you can send any information (<em>EBCDIC, ASCII, Hex, C arrays, Raw</em>) directly to the target server.<br class="C" /></p>
<h2>A Socket is like /dev/null</h2>
<p>In unix you can send anything to the <code>/dev/null</code> device, <em>for Windows think Recycle Bin</em>, and likewise you can send anything to a socket created with fsockopen.  I&#8217;ve seen fsockopen code that sends custom exploits to cisco routers, including being used by the metasploit framework.  I&#8217;ve seen fsockopen telnet emulation, smtp/pop3 login, and a lot of other advanced raw networking that is exciting for me see.</p>
<h3>Some Definitions for Fsockopen</h3>
<dl>
<dt><a href="http://www.askapache.com/glossary/#client" title="client">client</a></dt>
<dd>A program that establishes connections for the purpose of sending requests.</dd>
<dt><a href="http://www.askapache.com/glossary/#server" title="server">server</a></dt>
<dd>An application program that accepts connections in order to service requests by sending back responses.</dd>
</dl>
<h3>Simple Socket Explantion</h3>
<p>A web server host listens on TCP port 80.  When a client host wishes to view a resource on the web server, it establishes a TCP connection with the server host by opening a socket to send the request for the resource.  When the connection is established, the client and server exchange requests and responses (respectively) until the connection is closed or aborted.</p>
<h2>HTTP and fsockopen</h2>
<p><a href="http://snoopy.sourceforge.net/" rel="nofollow" class="IFR" href='http://www.askapache.com/php/speedy-form-post.html' title='Snoopy Fsockopen HTTP Class for PHP'><img src='http://uploads.askapache.com/2008/02/snoopy-fsockopen.thumbnail.png' alt='Snoopy Fsockopen HTTP Class for PHP' title="snoopy fsockopen.thumbnail web cache" /></a>The <a >Snoopy</a> class is bundled with WordPress distributions and uses fsockopen to achieve most of its cool features.  WordPress core, plugins, and other included files and classes also use the fsockopen function to communicate via HTTP.<br class="C" /></p>
<h2>Fsockopen Examples</h2>
<p><a rel="lb" class="IFL" href='http://uploads.askapache.com/2008/07/fsockopen-warning.jpg'><img src="http://uploads.askapache.com/2008/07/fsockopen-warning-200x181.jpg" alt="fsockopen warning" title="fsockopen warning" width="100" height="91" /></a>Note the warning sign, fsockopen is dangerous in the sense that you can crash your server, perform a DOS against your own server or other site, use up all your servers available sockets and fd descriptors, use up your bandwidth, etc.. Shouldn&#8217;t be a problem unless you are being malicious or careless.<br class="C" /></p>
<p>Here are some BOSS fsockopen functions I hacked together yesterday for use in my <a href="http://wordpress.org/extend/plugins/askapache-crazy-cache/" rel="nofollow" >AskApache Crazy Cache WordPress Plugin</a>.  I&#8217;ve used code and ideas from 100&#8242;s of authors, projects, and docs to try to make this the very best I can.</p>
<h3>Intro</h3>
<p>This is a working example employing as many of the best-practices, tips, and tricks for using fsockopen on remote streams that I could find.</p>
<pre>&lt;?php
// max time for script execution
if(!@defined(&#039;AA_MAX_TIME&#039;)) define(&#039;AA_MAX_TIME&#039;,  60);
&nbsp;
// max time for socket reads
if(!@defined(&#039;AA_RECV_TIME&#039;)) define(&#039;AA_RECV_TIME&#039;, 30);
&nbsp;
// max time for socket connect
if(!@defined(&#039;AA_CONN_TIME&#039;)) define(&#039;AA_CONN_TIME&#039;, 5);
&nbsp;
// linebreak
if(!@defined(&#039;AA_LF&#039;)) define(&#039;AA_LF&#039;, chr(13).chr(10));
&nbsp;
// ignore TCP RST i.e. browser stop button
@ignore_user_abort(1);
&nbsp;
// set the script execution time
@set_time_limit(AA_MAX_TIME);
&nbsp;
// set the default socket timeout value
@ini_set(&quot;default_socket_timeout&quot;,AA_RECV_TIME);
&nbsp;
// output implicitly
@ob_implicit_flush(1);
&nbsp;
// for binary freads
@set_magic_quotes_runtime(0);
&nbsp;
// keep track of script execution time
$aa_time=time();
&nbsp;
// download each of these urls using fsockopen
aa_dl(&#039;http://httpd.apache.org&#039;);
aa_dl(&#039;http://www.w3.org&#039;);
aa_dl(&#039;http://www.google.com&#039;);
aa_dl(&#039;http://www.freebsd.org/cgi/man.cgi?query=connect&amp;sektion=2&amp;apropos=0&amp;manpath=FreeBSD+7.0-RELEASE&#039;);
aa_dl(&#039;http://www.askapache.com/htaccess/htaccess.html&#039;);
aa_dl(&#039;http://www.php.net&#039;);
aa_dl(&#039;http://en.wikipedia.org/wiki/Main_Page&#039;);
&nbsp;
/*  returns a socket pointer if valid or displays an error message
    sets stream timeout, starts the clock to check for socket read time */
function askapache_get_sock($target,$port){
  global $aa_time_start;
  $aa_time_start=time();
  if(false===($fp = @fsockopen($target,$port,$errno,$errstr,AA_CONN_TIME))||!is_resource($fp))
    return askapache_sock_strerror($errno,$errstr);
  @stream_set_timeout($fp, AA_RECV_TIME);
  return $fp;
}
&nbsp;
/*  writes request, then reads response until EOF, script max, or socket max
    returns response on success.  Uses buffer to allow size&gt;100megs */
function askapache_txrx($fp,$request,$chunk=1024){
  $rec=$buf=&#039;&#039;;
  if(!@fwrite($fp, $request, strlen($request)))die(&#039;fwrite error&#039;);
  while ( !@feof($fp) &amp;&amp; askapache_time_ok(askapache_time_passed())){
    $buf = @fread($fp, $chunk);
    $rec .= $buf;
  }
  if(!@fclose($fp))die(&#039;fclose error&#039;);
  return $rec;
}
&nbsp;
/* initiates the socket and download for the passed url.
   automatically handles gzip, chunked, both, and plain downloads.
   uses the long2ip/ip2long for ip validation, uses gethostbyname to
   get the ipv4 address which saves fsockopen from having to do the lookup
   final data is saved to $rbody but currently only displays headers.*/
function aa_dl($url=NULL){
  global $aa_time;
  $ub = @parse_url($url);
  if(!isset($ub[&#039;host&#039;])||empty($ub[&#039;host&#039;])) die(&quot;bad url $url&quot;);
  $proto   = ($ub[&#039;scheme&#039;]==&#039;https&#039;)?&#039;ssl://&#039;:&#039;&#039;;
  $port   = (isset($ub[&#039;port&#039;])&amp;&amp;!empty($ub[&#039;port&#039;])) ? $ub[&#039;port&#039;]:($proto!=&#039;&#039;)?443:80;
  $path   = (isset($ub[&#039;path&#039;])&amp;&amp;!empty($ub[&#039;path&#039;])) ? $ub[&#039;path&#039;]:&#039;/&#039;;
  $query   = (isset($ub[&#039;query&#039;])&amp;&amp;!empty($ub[&#039;query&#039;])) ? &#039;?&#039;.$ub[&#039;query&#039;] : &#039;&#039;;
  $host   = $ub[&#039;host&#039;];
  $ipp     = @gethostbyname($host);
  $ip     = ($ipp!=$host) ? long2ip(ip2long($ipp)) : $host;

  $headers=array(
   &quot;GET {$path}{$query} HTTP/1.1&quot;,
   &quot;Host: {$host}&quot;,
   &#039;User-Agent: Mozilla/5.0 (AskApache/; +http://www.askapache.com/)&#039;,
   &#039;Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,*/*;q=0.5&#039;,
   &#039;Accept-Language: en-us,en;q=0.5&#039;,
   &#039;Accept-Encoding: gzip,deflate&#039;,
   &#039;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&#039;,
   &#039;Connection: close&#039;,&#039;Referer: http://www.askapache.com&#039;
  );
  $request=join(AA_LF,$headers).AA_LF.AA_LF;

  $fp=askapache_get_sock($proto.$ip, $port);
  if($fp){
    $rbody=$rec=&#039;&#039;;$resp_headers=array();
    $rec=askapache_txrx($fp,$request);
    list($resp_headers, $rbody) = explode(AA_LF.AA_LF, trim($rec), 2);
  echo &quot;\n&lt;p&gt;$request&lt;/p&gt;\n&lt;p&gt;$resp_headers&lt;/p&gt;\n&quot;;
    $gzip2=(stripos($resp_headers,&#039;Content-Encoding&#039;)!==false &amp;&amp;
        stripos($resp_headers,&#039;gzip&#039;)!==false)?1:0;
    $chunk=(stripos($resp_headers,&#039;Transfer-Encoding&#039;)!==false &amp;&amp;
        stripos($resp_headers,&#039;chunked&#039;)!==false)?1:0;
    $rbody=aa_decode_body($rbody,$chunk,$gzip2);
    unset($rbody);
  }
}
&nbsp;
/* based on http://us.php.net/manual/en/function.fsockopen.php#75175
   ungzips and/or re-assembles transfer-encoded:chunked responses
   returns the good response on success */
function aa_decode_body ($str, $chunked, $gzipped){
  if($gzipped &amp;&amp; !$chunked) return aa_gzdecode($str);
  if(!$gzipped &amp;&amp; !$chunked) return $str;
  $tmp = $str; $str = &#039;&#039;;
  do {
    $tmp = ltrim($tmp);
    $pos = strpos($tmp,AA_LF);
    $len = hexdec(substr($tmp, 0, $pos));
    if($gzipped) $str .= gzinflate(substr($tmp,($pos+12),$len));
    else $str .=substr($tmp,($pos+2),$len);
    $tmp = substr($tmp,($len+$pos+2));
  $chk=trim($tmp);
  } while (!empty($chk));
  return $str;
}
&nbsp;
/*  based on http://us2.php.net/manual/en/function.gzencode.php#82520
  saves the gzipped data to a tempfile, then outputs the decoded
  data to the output buffer using readgzfile, returning the decoded
  buffer and deleting the tempfile on success */
function aa_gzdecode($data){
  $g=tempnam(&#039;/tmp&#039;,&#039;ff&#039;);
  @file_put_contents($g,$data);
  ob_start(); readgzfile($g); $d=ob_get_clean(); @unlink($g);
  return $d;
}
&nbsp;
/*  very cool!  this is run during socket reads and checks whether the script
  execution time limit or the socket read time limit has been met, killing
  the script if so, otherwise returns true.  Run with a cron-like process */
function askapache_time_ok($sock_time=0) {
  global $aa_time;
  if (time()-$aa_time&gt;AA_MAX_TIME)
    die(&#039;killed script.. time exceeded &#039;.AA_MAX_TIME.&#039; Total: &#039;.$total);
  if ($sock_time&gt;AA_RECV_TIME)
    die(&#039;Killed socket.. time exceeded &#039;.AA_RECV_TIME.&#039; Total: &#039;.$sock_time);
  return true;
}
&nbsp;
/* input for askapache_time_ok to keep track of each socket read time time. */
function askapache_time_passed() {
  global $aa_time_start;
  return (time() - $aa_time_start);
}
&nbsp;
/*  handles fsockopen errors, printing them out though you may want to die on err */
function askapache_sock_strerror($errno,$errstr){
  switch($errno){
    case -3:  $err=&quot;Socket creation failed&quot;; break;
    case -4:  $err=&quot;DNS lookup failure&quot;; break;
    case -5:  $err=&quot;Connection refused or timed out&quot;; break;
    case 111: $err=&quot;Connection refused&quot;; break;
    case 113: $err=&quot;No route to host&quot;; break;
    case 110: $err=&quot;Connection timed out&quot;; break;
    case 104: $err=&quot;Connection reset by client&quot;; break;
    default:  $err=&quot;Connection failed&quot;; break;
  }
  echo &#039;&lt;p&gt;Fsockopen failed!&#039;.&quot;\n[&quot;.$errno.&quot;] &quot;.$err.&quot; (&quot;.$errstr.&quot;)&lt;/p&gt;&quot;;
  return false;
}
?&gt;</pre>
<hr class="C" />
<h2>Debugging Fsockopen</h2>
<p>If you really want to know more about fsockopen, you can do what I did and read all the relevant php source files, your OS sys, lib, and user files relevant to fsockopen, and of course you can always trace php using the fsockopen function to get an under-the-hood look at what in the world fsockopen is doing.  Personally, I was trying to find more error codes and error strings to display when an fsockopen call failed, and I ended up finding over 50..</p>
<h3>fsockopen Errors</h3>
<pre>function fsockopen_err($errnum)
{
   static $fsockopen_errors;
   is_null($fsockopen_errors) &amp;&amp; $fsockopen_errors = array(
  0 =&gt; &#039;Success&#039;,
  1 =&gt; &#039;Operation not permitted&#039;,
  2 =&gt; &#039;No such file or directory&#039;,
  3 =&gt; &#039;No such process&#039;,
  4 =&gt; &#039;Interrupted system call - DNS lookup failure&#039;,
  5 =&gt; &#039;Input/output error - Connection refused or timed out&#039;,
  6 =&gt; &#039;No such device or address&#039;,
  7 =&gt; &#039;Argument list too long&#039;,
  8 =&gt; &#039;Exec format error&#039;,
  9 =&gt; &#039;Bad file descriptor&#039;,
  10 =&gt; &#039;No child processes&#039;,
  11 =&gt; &#039;Resource temporarily unavailable&#039;,
  12 =&gt; &#039;Cannot allocate memory&#039;,
  13 =&gt; &#039;Permission denied&#039;,
  14 =&gt; &#039;Bad address&#039;,
  15 =&gt; &#039;Block device required&#039;,
  16 =&gt; &#039;Device or resource busy&#039;,
  17 =&gt; &#039;File exists&#039;,
  18 =&gt; &#039;Invalid cross-device link&#039;,
  19 =&gt; &#039;No such device&#039;,
  20 =&gt; &#039;Not a directory&#039;,
  21 =&gt; &#039;Is a directory&#039;,
  22 =&gt; &#039;Invalid argument&#039;,
  23 =&gt; &#039;Too many open files in system&#039;,
  24 =&gt; &#039;Too many open files&#039;,
  25 =&gt; &#039;Inappropriate ioctl for device&#039;,
  26 =&gt; &#039;Text file busy&#039;,
  27 =&gt; &#039;File too large&#039;,
  28 =&gt; &#039;No space left on device&#039;,
  29 =&gt; &#039;Illegal seek&#039;,
  30 =&gt; &#039;Read-only file system&#039;,
  31 =&gt; &#039;Too many links&#039;,
  32 =&gt; &#039;Broken pipe&#039;,
  33 =&gt; &#039;Numerical argument out of domain&#039;,
  34 =&gt; &#039;Numerical result out of range&#039;,
  35 =&gt; &#039;Resource deadlock avoided&#039;,
  36 =&gt; &#039;File name too long&#039;,
  37 =&gt; &#039;No locks available&#039;,
  38 =&gt; &#039;Function not implemented&#039;,
  39 =&gt; &#039;Directory not empty&#039;,
  40 =&gt; &#039;Too many levels of symbolic links&#039;,
  41 =&gt; &#039;Unknown error 41&#039;,
  42 =&gt; &#039;No message of desired type&#039;,
  43 =&gt; &#039;Identifier removed&#039;,
  44 =&gt; &#039;Channel number out of range&#039;,
  45 =&gt; &#039;Level 2 not synchronized&#039;,
  46 =&gt; &#039;Level 3 halted&#039;,
  47 =&gt; &#039;Level 3 reset&#039;,
  48 =&gt; &#039;Link number out of range&#039;,
  49 =&gt; &#039;Protocol driver not attached&#039;,
  50 =&gt; &#039;No CSI structure available&#039;,
  51 =&gt; &#039;Level 2 halted&#039;,
  52 =&gt; &#039;Invalid exchange&#039;,
  53 =&gt; &#039;Invalid request descriptor&#039;,
  54 =&gt; &#039;Exchange full&#039;,
  55 =&gt; &#039;No anode&#039;,
  56 =&gt; &#039;Invalid request code&#039;,
  57 =&gt; &#039;Invalid slot&#039;,
  58 =&gt; &#039;Unknown error 58&#039;,
  59 =&gt; &#039;Bad font file format&#039;,
  60 =&gt; &#039;Device not a stream&#039;,
  61 =&gt; &#039;No data available&#039;,
  62 =&gt; &#039;Timer expired&#039;,
  63 =&gt; &#039;Out of streams resources&#039;,
  64 =&gt; &#039;Machine is not on the network&#039;,
  65 =&gt; &#039;Package not installed&#039;,
  66 =&gt; &#039;Object is remote&#039;,
  67 =&gt; &#039;Link has been severed&#039;,
  68 =&gt; &#039;Advertise error&#039;,
  69 =&gt; &#039;Srmount error&#039;,
  70 =&gt; &#039;Communication error on send&#039;,
  71 =&gt; &#039;Protocol error&#039;,
  72 =&gt; &#039;Multihop attempted&#039;,
  73 =&gt; &#039;RFS specific error&#039;,
  74 =&gt; &#039;Bad message&#039;,
  75 =&gt; &#039;Value too large for defined data type&#039;,
  76 =&gt; &#039;Name not unique on network&#039;,
  77 =&gt; &#039;File descriptor in bad state&#039;,
  78 =&gt; &#039;Remote address changed&#039;,
  79 =&gt; &#039;Can not access a needed shared library&#039;,
  80 =&gt; &#039;Accessing a corrupted shared library&#039;,
  81 =&gt; &#039;.lib section in a.out corrupted&#039;,
  82 =&gt; &#039;Attempting to link in too many shared libraries&#039;,
  83 =&gt; &#039;Cannot exec a shared library directly&#039;,
  84 =&gt; &#039;Invalid or incomplete multibyte or wide character&#039;,
  85 =&gt; &#039;Interrupted system call should be restarted&#039;,
  86 =&gt; &#039;Streams pipe error&#039;,
  87 =&gt; &#039;Too many users&#039;,
  88 =&gt; &#039;Socket operation on non-socket&#039;,
  89 =&gt; &#039;Destination address required&#039;,
  90 =&gt; &#039;Message too long&#039;,
  91 =&gt; &#039;Protocol wrong type for socket&#039;,
  92 =&gt; &#039;Protocol not available&#039;,
  93 =&gt; &#039;Protocol not supported&#039;,
  94 =&gt; &#039;Socket type not supported&#039;,
  95 =&gt; &#039;Operation not supported&#039;,
  96 =&gt; &#039;Protocol family not supported&#039;,
  97 =&gt; &#039;Address family not supported by protocol&#039;,
  98 =&gt; &#039;Address already in use&#039;,
  99 =&gt; &#039;Cannot assign requested address&#039;,
  100 =&gt; &#039;Network is down&#039;,
  101 =&gt; &#039;Network is unreachable&#039;,
  102 =&gt; &#039;Network dropped connection on reset&#039;,
  103 =&gt; &#039;Software caused connection abort&#039;,
  104 =&gt; &#039;Connection reset by peer&#039;,
  105 =&gt; &#039;No buffer space available&#039;,
  106 =&gt; &#039;Transport endpoint is already connected&#039;,
  107 =&gt; &#039;Transport endpoint is not connected&#039;,
  108 =&gt; &#039;Cannot send after transport endpoint shutdown&#039;,
  109 =&gt; &#039;Too many references: cannot splice&#039;,
  110 =&gt; &#039;Connection timed out&#039;,
  111 =&gt; &#039;Connection refused&#039;,
  112 =&gt; &#039;Host is down&#039;,
  113 =&gt; &#039;No route to host&#039;,
  114 =&gt; &#039;Operation already in progress&#039;,
  115 =&gt; &#039;Operation now in progress&#039;,
  116 =&gt; &#039;Stale NFS file handle&#039;,
  117 =&gt; &#039;Structure needs cleaning&#039;,
  118 =&gt; &#039;Not a XENIX named type file&#039;,
  119 =&gt; &#039;No XENIX semaphores available&#039;,
  120 =&gt; &#039;Is a named type file&#039;,
  121 =&gt; &#039;Remote I/O error&#039;,
  122 =&gt; &#039;Disk quota exceeded&#039;,
  123 =&gt; &#039;No medium found&#039;,
  124 =&gt; &#039;Wrong medium type&#039;,
  125 =&gt; &#039;Operation canceled&#039;
  );
    return (isset($fsockopen_errors[$errnum])) ? $fsockopen_errors[$errnum] : $errnum;
}</pre>
<p>If you would like to see all the errors on your particular machine:</p>
<pre>for($i=0, $s=&quot;&quot;; $i&lt;250; $s=socket_strerror($i), $i++)
  !empty($s) &amp;&amp; (&#039;Unknown error&#039; != (substr($s,0,13)) ) &amp;&amp; print &quot;{$i} =&gt; {$s}\n&quot;;</pre>
<p>Which outputs:</p>
<pre>1 =&gt; Success
2 =&gt; Operation not permitted
3 =&gt; No such file or directory
4 =&gt; No such process
5 =&gt; Interrupted system call
6 =&gt; Input/output error
7 =&gt; No such device or address
8 =&gt; Argument list too long
9 =&gt; Exec format error
10 =&gt; Bad file descriptor
11 =&gt; No child processes
12 =&gt; Resource temporarily unavailable
13 =&gt; Cannot allocate memory
14 =&gt; Permission denied
15 =&gt; Bad address
16 =&gt; Block device required
17 =&gt; Device or resource busy
18 =&gt; File exists
19 =&gt; Invalid cross-device link
20 =&gt; No such device
21 =&gt; Not a directory
22 =&gt; Is a directory
23 =&gt; Invalid argument
24 =&gt; Too many open files in system
25 =&gt; Too many open files
26 =&gt; Inappropriate ioctl for device
27 =&gt; Text file busy
28 =&gt; File too large
29 =&gt; No space left on device
30 =&gt; Illegal seek
31 =&gt; Read-only file system
32 =&gt; Too many links
33 =&gt; Broken pipe
34 =&gt; Numerical argument out of domain
35 =&gt; Numerical result out of range
36 =&gt; Resource deadlock avoided
37 =&gt; File name too long
38 =&gt; No locks available
39 =&gt; Function not implemented
40 =&gt; Directory not empty
41 =&gt; Too many levels of symbolic links
43 =&gt; No message of desired type
44 =&gt; Identifier removed
45 =&gt; Channel number out of range
46 =&gt; Level 2 not synchronized
47 =&gt; Level 3 halted
48 =&gt; Level 3 reset
49 =&gt; Link number out of range
50 =&gt; Protocol driver not attached
51 =&gt; No CSI structure available
52 =&gt; Level 2 halted
53 =&gt; Invalid exchange
54 =&gt; Invalid request descriptor
55 =&gt; Exchange full
56 =&gt; No anode
57 =&gt; Invalid request code
58 =&gt; Invalid slot
60 =&gt; Bad font file format
61 =&gt; Device not a stream
62 =&gt; No data available
63 =&gt; Timer expired
64 =&gt; Out of streams resources
65 =&gt; Machine is not on the network
66 =&gt; Package not installed
67 =&gt; Object is remote
68 =&gt; Link has been severed
69 =&gt; Advertise error
70 =&gt; Srmount error
71 =&gt; Communication error on send
72 =&gt; Protocol error
73 =&gt; Multihop attempted
74 =&gt; RFS specific error
75 =&gt; Bad message
76 =&gt; Value too large for defined data type
77 =&gt; Name not unique on network
78 =&gt; File descriptor in bad state
79 =&gt; Remote address changed
80 =&gt; Can not access a needed shared library
81 =&gt; Accessing a corrupted shared library
82 =&gt; .lib section in a.out corrupted
83 =&gt; Attempting to link in too many shared libraries
84 =&gt; Cannot exec a shared library directly
85 =&gt; Invalid or incomplete multibyte or wide character
86 =&gt; Interrupted system call should be restarted
87 =&gt; Streams pipe error
88 =&gt; Too many users
89 =&gt; Socket operation on non-socket
90 =&gt; Destination address required
91 =&gt; Message too long
92 =&gt; Protocol wrong type for socket
93 =&gt; Protocol not available
94 =&gt; Protocol not supported
95 =&gt; Socket type not supported
96 =&gt; Operation not supported
97 =&gt; Protocol family not supported
98 =&gt; Address family not supported by protocol
99 =&gt; Address already in use
100 =&gt; Cannot assign requested address
101 =&gt; Network is down
102 =&gt; Network is unreachable
103 =&gt; Network dropped connection on reset
104 =&gt; Software caused connection abort
105 =&gt; Connection reset by peer
106 =&gt; No buffer space available
107 =&gt; Transport endpoint is already connected
108 =&gt; Transport endpoint is not connected
109 =&gt; Cannot send after transport endpoint shutdown
110 =&gt; Too many references: cannot splice
111 =&gt; Connection timed out
112 =&gt; Connection refused
113 =&gt; Host is down
114 =&gt; No route to host
115 =&gt; Operation already in progress
116 =&gt; Operation now in progress
117 =&gt; Stale NFS file handle
118 =&gt; Structure needs cleaning
119 =&gt; Not a XENIX named type file
120 =&gt; No XENIX semaphores available
121 =&gt; Is a named type file
122 =&gt; Remote I/O error
123 =&gt; Disk quota exceeded
124 =&gt; No medium found
125 =&gt; Wrong medium type
126 =&gt; Operation canceled</pre>
<h3>Tracing fsockopen using Strace</h3>
<p>Once you save the above file on your site, you can use the strace tool to debug it.  This is a tad overboard but way cool nevertheless!</p>
<p><code>strace -e trace=connect php -nef fsockopen-test.php</code></p>
<pre>connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;192.87.106.226&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)</pre>
<p><code>strace -e trace=network php -nef fsockopen-test.php</code></p>
<pre>socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path=&quot;/var/run/.nscd_socket&quot;}, 110) = -1 ENOENT (No such file or directory)
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
send(3, &quot;\274\221\1\0\0\1\0\0\0\0\0\0\5httpd\6apache\3org\0\0\1&quot;&#46;.., 34, 0) = 34
recvfrom(3, &quot;\274\221\201\200\0\1\0\1\0\0\0\0\5httpd\6apache\3org\0&quot;&#46;.., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, [16]) = 50
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = -1 EAFNOSUPPORT (Address family not supported by protocol)
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;192.87.106.226&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
send(3, &quot;GET / HTTP/1.1\r\nHost: httpd.apac&quot;&#46;.., 356, MSG_DONTWAIT) = 356
recv(3, &quot;HTTP/1.1 200 OK\r\nDate: Wed, 02 J&quot;&#46;.., 8192, MSG_DONTWAIT) = 2609
recv(3, &quot;&quot;, 8192, MSG_DONTWAIT)         = 0</pre>
<p><code>strace -q -e trace=all php -nef fsockopen-test.php</code></p>
<pre>mmap2(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76ba000
munmap(0xb76ba000, 266240)              = 0
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path=&quot;/var/run/.nscd_socket&quot;}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open(&quot;/etc/hosts&quot;, O_RDONLY)            = 3
fcntl64(3, F_GETFD)                     = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=948, &#46;..}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f6e000
read(3, &quot;# /etc/hosts - dh2 generated\n127&quot;&#46;.., 4096) = 948
read(3, &quot;&quot;, 4096)                       = 0
close(3)                                = 0
munmap(0xb7f6e000, 4096)                = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
send(3, &quot;X~\1\0\0\1\0\0\0\0\0\0\2en\twikipedia\3org\0\0\1&quot;&#46;.., 34, 0) = 34
gettimeofday({1214998196, 656179}, NULL) = 0
poll([{fd=3, events=POLLIN, revents=POLLIN}], 1, 5000) = 1
ioctl(3, FIONREAD, [100])               = 0
recvfrom(3, &quot;X~\201\200\0\1\0\3\0\0\0\0\2en\twikipedia\3org\0\0\1&quot;&#46;.., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, [16]) = 100
close(3)                                = 0
time(NULL)                              = 1214998196
gettimeofday({1214998196, 656754}, NULL) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;208.80.152.2&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP, revents=POLLOUT}], 1, 10000) = 1
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR)             = 0
send(3, &quot;GET /wiki/Main_Page HTTP/1.1\r\nHo&quot;&#46;.., 370, MSG_DONTWAIT) = 370
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0
time(NULL)                              = 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;HTTP/1.0 200 OK\r\nDate: Wed, 02 J&quot;&#46;.., 8192, MSG_DONTWAIT) = 2896
time(NULL)                              = 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;\214!\337i\307\336\23w\253wy\215\26EL\227;\227\253\261&quot;&#46;.., 8192, MSG_DONTWAIT) = 5792
time(NULL)                              = 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;4\201\273\214\17yI\347\257\371\373\344\332\330\227\245&quot;&#46;.., 8192, MSG_DONTWAIT) = 7487
time(NULL)                              = 1214998197
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;&quot;, 8192, MSG_DONTWAIT)         = 0
close(3)                                = 0
write(1, &quot;\n&lt;pre&gt;GET /wiki/Main_Page HTTP/1&quot;&#46;.., 1300</pre>
<hr class="C" />
<h2>More Fsockopen Info</h2>
<h3>TCP Multiplexing</h3>
<p><a href="http://rfc.askapache.com/rfc793/rfc793.html#page-10" rel="nofollow" >RFC 793</a>: To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host.  Concatenated with the network and host addresses from the internet communication layer, this forms a socket.  A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.</p>
<p>The binding of ports to processes is handled independently by each Host.  However, it proves useful to attach frequently used processes (e.g., a &#8220;logger&#8221; or timesharing service) to fixed sockets which are made known to the public.  These services can then be accessed through the known addresses.  Establishing and learning the port addresses of other processes may involve more dynamic mechanisms.</p>
<h3>TCP Connections</h3>
<p>The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream.  The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.</p>
<p>When two processes wish to communicate, their TCP&#8217;s must first establish a connection (initialize the status information on each side).  When their communication is complete, the connection is terminated or closed to free the resources for other uses.</p>
<p>Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.</p>
<h3>Fsockopen Practical Uses</h3>
<ul>
<li>Download Web Pages, Files, etc.</li>
<li><a href="http://www.askapache.com/php/speedy-form-post.html">Upload a file</a></li>
<li><a href="http://www.askapache.com/php/speedy-form-post.html">Send POST data to a form</a></li>
<li>Emulate cron</li>
<li>Download plugin updates</li>
<li><a href="http://www.askapache.com/online-tools/request-method-scanner/">Scan sites for exploits</a></li>
<li><a href="http://www.askapache.com/online-tools/curl-google-feed/">Auto Login to Google</a></li>
<li><a href="http://www.askapache.com/wordpress/crazy-cache-wordpress-plugin.html">Pass wp-nonces via cookie headers</a>, and more</li>
</ul>
<h3>Transfer-Encoding</h3>
<p><a href="http://www.ietf.org/rfc/rfc2068" rel="nofollow" >RFC 2068</a></p>
<pre>19.4.6 Introduction of Transfer-Encoding
&nbsp;
   HTTP/1.1 introduces the Transfer-Encoding header field (section
   14.40).  Proxies/gateways MUST remove any transfer coding prior to
   forwarding a message via a MIME-compliant protocol.
&nbsp;
   A process for decoding the &quot;chunked&quot; transfer coding (section 3.6)
   can be represented in pseudo-code as:
&nbsp;
          length := 0
          read chunk-size, chunk-ext (if any) and CRLF
          while (chunk-size &gt; 0) {
             read chunk-data and CRLF
             append chunk-data to entity-body
             length := length + chunk-size
             read chunk-size and CRLF
          }
          read entity-header
          while (entity-header not empty) {
             append entity-header to existing header fields
             read entity-header
          }
          Content-Length := length
          Remove &quot;chunked&quot; from Transfer-Encoding</pre>
<h3>Socket-Related Man Pages</h3>
<pre>DESCRIPTION
This  manual  page  describes the Linux networking socket layer user interface. The BSD compatible sockets are the uniform interface between
the user process and the network protocol stacks in the kernel.  The protocol modules are  grouped  into  protocol  families  like  PF_INET,
PF_IPX, PF_PACKET and socket types like SOCK_STREAM or SOCK_DGRAM.  See socket(2) for more information on families and types.
&nbsp;
SOCKET LAYER FUNCTIONS
These  functions  are  used by the user process to send or receive packets and to do other socket operations. For more information see their
respective manual pages.
&nbsp;
socket(2) creates a socket, connect(2) connects a socket to a remote socket address, the bind(2) function binds a socket to a  local  socket
address,  listen(2)  tells  the socket that new connections shall be accepted, and accept(2) is used to get a new socket with a new incoming
connection.  socketpair(2) returns two connected anonymous sockets (only implemented for a few local families like PF_UNIX)
&nbsp;
send(2), sendto(2), and sendmsg(2) send data over a socket, and recv(2), recvfrom(2), recvmsg(2) receive data from a  socket.   poll(2)  and
select(2)  wait  for  arriving  data  or a readiness to send data.  In addition, the standard I/O operations like write(2), writev(2), send-
file(2), read(2), and readv(2) can be used to read and write data.
&nbsp;
getsockname(2) returns the local socket address and getpeername(2) returns the remote socket address.  getsockopt(2) and  setsockopt(2)  are
used to set or get socket layer or protocol options.  ioctl(2) can be used to set or read some other options.
&nbsp;
close(2) is used to close a socket.  shutdown(2) closes parts of a full duplex socket connection.
&nbsp;
Seeking, or calling pread(2) or pwrite(2) with a non-zero position is not supported on sockets.
&nbsp;
It  is possible to do non-blocking IO on sockets by setting the O_NONBLOCK flag on a socket file descriptor using fcntl(2).  Then all opera-
tions that would block will (usually) return with EAGAIN (operation should be retried later); connect(2) will return EINPROGRESS error.  The
user can then wait for various events via poll(2) or select(2).</pre>
<p>From the <a href="http://www.freebsd.org/cgi/man.cgi?query=socket&#038;sektion=2&#038;apropos=0&#038;manpath=FreeBSD+7.0-RELEASE" rel="nofollow" >FreeBSD man page for socket(2)</a></p>
<pre>Sockets of type SOCK_STREAM are full-duplex byte streams, similar to
pipes.  A stream socket must be in a connected state before any data may
be sent or received on it.  A connection to another socket is created
with a connect(2) system call.  Once connected, data may be transferred
using read(2) and write(2) calls or some variant of the send(2) and
recv(2) functions.  (Some protocol families, such as the Internet family,
support the notion of an &#96;`implied connect&#039;&#039;, which permits data to be
sent piggybacked onto a connect operation by using the sendto(2) system
call.)  When a session has been completed a close(2) may be performed.
Out-of-band data may also be transmitted as described in send(2) and
received as described in recv(2).
&nbsp;
The communications protocols used to implement a SOCK_STREAM insure that
data is not lost or duplicated.  If a piece of data for which the peer
protocol has buffer space cannot be successfully transmitted within a
reasonable length of time, then the connection is considered broken and
calls will indicate an error with -1 returns and with ETIMEDOUT as the
specific code in the global variable errno.  The protocols optionally
keep sockets &#96;`warm&#039;&#039; by forcing transmissions roughly every minute in
the absence of other activity.  An error is then indicated if no response
can be elicited on an otherwise idle connection for an extended period
(e.g. 5 minutes).  A SIGPIPE signal is raised if a process sends on a
broken stream; this causes naive processes, which do not handle the sig-
nal, to exit.</pre>
<p>Have Fun   ;)</p>
<pre>define (&#039;SOCKET_EPERM&#039;, 1);
define (&#039;SOCKET_ENOENT&#039;, 2);
define (&#039;SOCKET_EINTR&#039;, 4);
define (&#039;SOCKET_EIO&#039;, 5);
define (&#039;SOCKET_ENXIO&#039;, 6);
define (&#039;SOCKET_E2BIG&#039;, 7);
define (&#039;SOCKET_EBADF&#039;, 9);
define (&#039;SOCKET_EAGAIN&#039;, 11);
define (&#039;SOCKET_ENOMEM&#039;, 12);
define (&#039;SOCKET_EACCES&#039;, 13);
define (&#039;SOCKET_EFAULT&#039;, 14);
define (&#039;SOCKET_ENOTBLK&#039;, 15);
define (&#039;SOCKET_EBUSY&#039;, 16);
define (&#039;SOCKET_EEXIST&#039;, 17);
define (&#039;SOCKET_EXDEV&#039;, 18);
define (&#039;SOCKET_ENODEV&#039;, 19);
define (&#039;SOCKET_ENOTDIR&#039;, 20);
define (&#039;SOCKET_EISDIR&#039;, 21);
define (&#039;SOCKET_EINVAL&#039;, 22);
define (&#039;SOCKET_ENFILE&#039;, 23);
define (&#039;SOCKET_EMFILE&#039;, 24);
define (&#039;SOCKET_ENOTTY&#039;, 25);
define (&#039;SOCKET_ENOSPC&#039;, 28);
define (&#039;SOCKET_ESPIPE&#039;, 29);
define (&#039;SOCKET_EROFS&#039;, 30);
define (&#039;SOCKET_EMLINK&#039;, 31);
define (&#039;SOCKET_EPIPE&#039;, 32);
define (&#039;SOCKET_ENAMETOOLONG&#039;, 36);
define (&#039;SOCKET_ENOLCK&#039;, 37);
define (&#039;SOCKET_ENOSYS&#039;, 38);
define (&#039;SOCKET_ENOTEMPTY&#039;, 39);
define (&#039;SOCKET_ELOOP&#039;, 40);
define (&#039;SOCKET_EWOULDBLOCK&#039;, 11);
define (&#039;SOCKET_ENOMSG&#039;, 42);
define (&#039;SOCKET_EIDRM&#039;, 43);
define (&#039;SOCKET_ECHRNG&#039;, 44);
define (&#039;SOCKET_EL2NSYNC&#039;, 45);
define (&#039;SOCKET_EL3HLT&#039;, 46);
define (&#039;SOCKET_EL3RST&#039;, 47);
define (&#039;SOCKET_ELNRNG&#039;, 48);
define (&#039;SOCKET_EUNATCH&#039;, 49);
define (&#039;SOCKET_ENOCSI&#039;, 50);
define (&#039;SOCKET_EL2HLT&#039;, 51);
define (&#039;SOCKET_EBADE&#039;, 52);
define (&#039;SOCKET_EBADR&#039;, 53);
define (&#039;SOCKET_EXFULL&#039;, 54);
define (&#039;SOCKET_ENOANO&#039;, 55);
define (&#039;SOCKET_EBADRQC&#039;, 56);
define (&#039;SOCKET_EBADSLT&#039;, 57);
define (&#039;SOCKET_ENOSTR&#039;, 60);
define (&#039;SOCKET_ENODATA&#039;, 61);
define (&#039;SOCKET_ETIME&#039;, 62);
define (&#039;SOCKET_ENOSR&#039;, 63);
define (&#039;SOCKET_ENONET&#039;, 64);
define (&#039;SOCKET_EREMOTE&#039;, 66);
define (&#039;SOCKET_ENOLINK&#039;, 67);
define (&#039;SOCKET_EADV&#039;, 68);
define (&#039;SOCKET_ESRMNT&#039;, 69);
define (&#039;SOCKET_ECOMM&#039;, 70);
define (&#039;SOCKET_EPROTO&#039;, 71);
define (&#039;SOCKET_EMULTIHOP&#039;, 72);
define (&#039;SOCKET_EBADMSG&#039;, 74);
define (&#039;SOCKET_ENOTUNIQ&#039;, 76);
define (&#039;SOCKET_EBADFD&#039;, 77);
define (&#039;SOCKET_EREMCHG&#039;, 78);
define (&#039;SOCKET_ERESTART&#039;, 85);
define (&#039;SOCKET_ESTRPIPE&#039;, 86);
define (&#039;SOCKET_EUSERS&#039;, 87);
define (&#039;SOCKET_ENOTSOCK&#039;, 88);
define (&#039;SOCKET_EDESTADDRREQ&#039;, 89);
define (&#039;SOCKET_EMSGSIZE&#039;, 90);
define (&#039;SOCKET_EPROTOTYPE&#039;, 91);
define (&#039;SOCKET_ENOPROTOOPT&#039;, 92);
define (&#039;SOCKET_EPROTONOSUPPORT&#039;, 93);
define (&#039;SOCKET_ESOCKTNOSUPPORT&#039;, 94);
define (&#039;SOCKET_EOPNOTSUPP&#039;, 95);
define (&#039;SOCKET_EPFNOSUPPORT&#039;, 96);
define (&#039;SOCKET_EAFNOSUPPORT&#039;, 97);
define (&#039;SOCKET_EADDRINUSE&#039;, 98);
define (&#039;SOCKET_EADDRNOTAVAIL&#039;, 99);
define (&#039;SOCKET_ENETDOWN&#039;, 100);
define (&#039;SOCKET_ENETUNREACH&#039;, 101);
define (&#039;SOCKET_ENETRESET&#039;, 102);
define (&#039;SOCKET_ECONNABORTED&#039;, 103);
define (&#039;SOCKET_ECONNRESET&#039;, 104);
define (&#039;SOCKET_ENOBUFS&#039;, 105);
define (&#039;SOCKET_EISCONN&#039;, 106);
define (&#039;SOCKET_ENOTCONN&#039;, 107);
define (&#039;SOCKET_ESHUTDOWN&#039;, 108);
define (&#039;SOCKET_ETOOMANYREFS&#039;, 109);
define (&#039;SOCKET_ETIMEDOUT&#039;, 110);
define (&#039;SOCKET_ECONNREFUSED&#039;, 111);
define (&#039;SOCKET_EHOSTDOWN&#039;, 112);
define (&#039;SOCKET_EHOSTUNREACH&#039;, 113);
define (&#039;SOCKET_EALREADY&#039;, 114);
define (&#039;SOCKET_EINPROGRESS&#039;, 115);
define (&#039;SOCKET_EISNAM&#039;, 120);
define (&#039;SOCKET_EREMOTEIO&#039;, 121);
define (&#039;SOCKET_EDQUOT&#039;, 122);
define (&#039;SOCKET_ENOMEDIUM&#039;, 123);
define (&#039;SOCKET_EMEDIUMTYPE&#039;, 124);</pre>
<ul>
<li><a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html" rel="nofollow" >Hypertext Transfer Protocol — HTTP/1.1</a>, RFC 2616.  R. Fielding <em>et al.</em></li>
<li><a href="http://www.w3.org/Talks/9608HTTP/index.htm" rel="nofollow" > Hypertext ransport Protocol HTTP/1.1</a>.  J. Gettys. (slides)</li>
<li><a href="http://www.usenix.org/publications/library/proceedings/usenix99/invited_talks/mogul.pdf" rel="nofollow" >What&#8217;s wrong with HTTP (and why it doesn&#8217;t matter)</a>.J. C. Mogul. (PDF slides)</li>
<li><a href="http://www.w3.org/Protocols/HTTP/Performance/Pipeline.html" rel="nofollow" >Network Performance Effects of HTTP/1.1, CSS1, and PNG</a>.H. F. Nielsen, J. Gettys <em>et al.</em></li>
<li>Mozilla&#8217;s <a href="http://www.mozilla.org/projects/netlib/http/pipelining-faq.html" rel="nofollow" >HTTP/1.1 Pipelining FAQ</a>. D. Fisher.</li>
<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/HTTP_proxy" rel="nofollow" >HTTP proxy</a>.</li>
</ul>
<p><a href="http://www.askapache.com/php/fsockopen-socket.html"></a><a href="http://www.askapache.com/php/fsockopen-socket.html">Fsockopen Power Plays</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/php/fsockopen-socket.html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
