<?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>Ciarpame {.com} &#187; Apache</title>
	<atom:link href="http://www.ciarpame.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ciarpame.com</link>
	<description>Useful stuffs for the masses. Useless things for few.</description>
	<lastBuildDate>Tue, 01 Dec 2009 13:03:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha</generator>
		<item>
		<title>Far Future Expires Header: come e perchè (IIS, Apache, Tomcat, PHP, ASP, JSP)</title>
		<link>http://www.ciarpame.com/2009/01/14/far-future-expires-header-come-e-perche-iis-apache-tomcat-php-asp-jsp/</link>
		<comments>http://www.ciarpame.com/2009/01/14/far-future-expires-header-come-e-perche-iis-apache-tomcat-php-asp-jsp/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 11:42:12 +0000</pubDate>
		<dc:creator>Giovanni Savastano</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.ciarpame.com/?p=415</guid>
		<description><![CDATA[Sempre più spesso, nel mondo dello sviluppo web, si sente parlare di aumento delle performance, dimunuzione delle richieste HTTP, caching di contenuti dinamici, compressione di immagini e altre tecniche orientate all&#8217;allegerimento delle pagine di un sito e all&#8217;aumento della visualizzazione sul computer del nostro caro visitatore. Sicuramente una condizione ottimale per ottenere prestazioni migliori della [...]]]></description>
			<content:encoded><![CDATA[<p>Sempre più spesso, nel mondo dello sviluppo web, si sente parlare di aumento delle performance, dimunuzione delle richieste HTTP, caching di contenuti dinamici, compressione di immagini e altre tecniche orientate all&#8217;allegerimento delle pagine di un sito e all&#8217;aumento della visualizzazione sul computer del nostro caro visitatore.</p>
<p>Sicuramente una condizione ottimale per ottenere prestazioni migliori della propria web app o del proprio sito web è impostare il cosidetto <span style="text-decoration: underline;">Far Future Expire Header</span> degli elementi prensenti nelle pagine e delle pagine stesse.</p>
<p>In questo post cercherò di descrivere alcune tecniche per impostare tale condizione.</p>
<p><span id="more-415"></span></p>
<p>Cito dal sito di <a title="YSlow for Firebug" href="http://developer.yahoo.com/yslow/" target="_blank">YSlow</a>:</p>
<blockquote><p>Web page designs are getting richer and richer, which means more scripts, stylesheets, images, and Flash in the page. A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on <em>all</em> components including scripts, stylesheets, and Flash components.</p></blockquote>
<p>Quindi in pratica che fa?:-)</p>
<p>L&#8217;Expire Header definisce la scadenza dell&#8217;oggetto che il browser preleva dal server e deposita nella cache del client. Impostando la &#8220;data di scadenza&#8221; ad un periodo molto lontano (Far Future per l&#8217;appunto) diciamo al browser di non richiamare più tale componente durante le succesive visite alla pagina che lo conteneva, rendendo di fatto la navigazione più veloce. Inoltre, applicando questa tecnica ad elementi comuni a tutte le pagine (es: background o file javascript o file css) l&#8217;utente usufruirà dei benefici di questa tecnica fin dalla seconda pagina che andrà a visualizzare sul nostro sito.</p>
<p>Vediamo come fare.</p>
<p><strong>Tramite l&#8217;uso di .htaccess (Apache)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|php|html|htm|php4|php5)$&quot;&gt;
Header set Expires &quot;Thu, 2 Feb 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;</pre></div></div>

<p>con l&#8217;istruzione FileMatch indichiamo a quale tipo di file applicare le regole all&#8217;interno del blocco di codice e con &#8220;Header set Expires&#8221; andremo a dire ad Apache di <i>servire</i> il contenuto indicato con una data di scadenza molto lontana. Nell&#8217;esempio ho usato il 2 Febbraio 2010, alle 8 di sera.</p>
<p><strong>Tramite le impostazioni di IIS 6.0</strong></p>
<ol>
<li>Aprite il pannello di controllo di Internet Information Services (IIS).</li>
<li>Espandete &#8220;LocalMachine&#8221; sul pannelo di sinistra e succesivamente cliccate su Web Sites</li>
<li>Click con il tasto destro sul sito interessato e selezionate Properties.</li>
<li>Nel tab HTTP Headers, attivate la checkbox &#8220;Enable Content Expiration&#8221; e succesivamente selezionate l&#8217;opzione &#8220;Expire On&#8221;. e impostare il 2 Febbraio 2010 alle 8 di sera</li>
<li>Riavviate tutti i servizi IIS.</li>
</ol>
<p><strong>Con PHP</strong><br />
File far_future_loader.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/javascript; charset: UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/scripts.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>con il codice sopra potete, ad esempio, raggruppare tutti i vostri file javascript in un unico grande file .php, modificare l&#8217;header Content-type in modo che venga interpretato correttamente dal browser come text/javascript e poi modificarne a piaciemento la deata di scandenza.<br />
Successivamente nell&#8217;header delle vostre pagine, anzichè includere i singoli file javascript con l&#8217;istruzione:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;js/scripts.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>userete</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;js/far_future_loader.php&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Potete usare il file far_future_loader.php per ogni tipo di file, semplicemente cambiano il Content-type dei file che andrete ad includere, ad esempio, se volete averne uno anche per i file .css dovrete scrivere:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/css; charset: UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D, d M Y H:i:s&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/style.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>e successivamente nell&#8217;header delle vostre pagine, esattamente come avete fatto per il file javascript, sostituirete l&#8217;istruzione:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>con</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/far_future_loader.php&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p><strong>Con ASP</strong><br />
la procedura è identica a quella per PHP con la sola differenza che in ASP gli header si setttano con i seguenti comandi:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">CacheControl</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;must-revalidate&quot;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;%</span> <span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Expires</span> <span style="color: #006600; font-weight: bold;">=</span> -<span style="color: #800000;">1</span> <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p><strong>Con JSP (Tomcat)</strong><br />
Grazie a <a href="http://www.jguru.com/guru/viewfaqs.jsp?EID=1168738" target="_blank">Byron Tymvios</a> su <a target="_blank" href="http://www.jguru.com/faq/view.jsp?EID=1311010">jGuru</a><br />
E&#8217; possibile ottenere l&#8217;identico risultato avuto con PHP o ASP tramite i filtri. Ad esempio:</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">package com.xyz
&nbsp;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
&nbsp;
public class CacheFilter implements javax.servlet.Filter {
  FilterConfig filterConfig = null;
&nbsp;
  public void init(FilterConfig filterConfig){
    this.filterConfig = filterConfig;
  }
&nbsp;
  public void doFilter(ServletRequest req,
     ServletResponse res,
     FilterChain chain)
     throws IOException, ServletException {
    String sCache = filterConfig.getInitParameter(&quot;cache&quot;);
&nbsp;
    if(sCache != null){       ((HttpServletResponse)res).setHeader(&quot;Cache-Control&quot;, sCache);
&nbsp;
    }
&nbsp;
    chain.doFilter(req, res);
  }
&nbsp;
  public void destroy(){
    this.filterConfig = null;
  }
}</pre></div></div>

<p>e poi impostare nel file web.xml il filtro per ogni contenuto desiderato. Ecco l&#8217;esempio per i file .jpg:</p>

<div class="wp_syntax"><div class="code"><pre class="jsp" style="font-family:monospace;">&lt;filter&gt;
  &lt;filter-name&gt;Cache&lt;/filter-name&gt;
  &lt;filter-class&gt;com.xyz.CacheFilter&lt;/filter-class&gt;
  &lt;init-param&gt;
    &lt;param-name&gt;cache&lt;/param-name&gt;
    &lt;param-value&gt;public, max-age=2592000&lt;/param-value&gt;
  &lt;/init-param&gt;
&lt;/filter&gt;
&lt;filter-mapping&gt;
  &lt;filter-name&gt;Cache&lt;/filter-name&gt;
  &lt;url-pattern&gt;*.jpg&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;</pre></div></div>

<p>è tutto <img src='http://www.ciarpame.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
nella prossimo post parleremo degli ETag.<br />
Giovanni</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ciarpame.com/2009/01/14/far-future-expires-header-come-e-perche-iis-apache-tomcat-php-asp-jsp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>cambiare facilmente il docroot di suexec su Debian (sarge/lenny/etch).</title>
		<link>http://www.ciarpame.com/2008/10/27/cambiare-facilmente-il-docroot-di-suexec-su-debian-sargelennyetch/</link>
		<comments>http://www.ciarpame.com/2008/10/27/cambiare-facilmente-il-docroot-di-suexec-su-debian-sargelennyetch/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 07:00:05 +0000</pubDate>
		<dc:creator>Giovanni Savastano</dc:creator>
				<category><![CDATA[Linux&Co.]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[suexec]]></category>

		<guid isPermaLink="false">http://www.ciarpame.com/?p=264</guid>
		<description><![CDATA[Una delle cose più fastidiose di apache è che, se compilato senza attenzione, si porta dietro una serie di configurazioni non modificabili tramite semplici file di configurazione. Alcune di queste sono sicuramente i parametri di suexec. Suexec è una funzionalità presente in apache 1.2 che permette di eseguire CGI e applicazioni SSI con i privilegi [...]]]></description>
			<content:encoded><![CDATA[<p>Una delle cose più fastidiose di apache è che, se compilato senza attenzione, si porta dietro una serie di configurazioni non modificabili tramite semplici file di configurazione.<br />
Alcune di queste sono sicuramente i parametri di suexec.<br />
Suexec è una funzionalità presente in apache 1.2 che permette di eseguire CGI e applicazioni SSI con i privilegi diversi da quelli dell&#8217;utente apache di sistema. In questo modo ogni utente può eseguire scripts complessi senza poter uscire dal proprio spazio web.</p>
<p>Purtoppo a volte è necessario modificare i path di default.<br />
Vediamo come</p>
<p><span id="more-264"></span></p>
<p>Innanzitutto loggatevi sulla vostra macchina con privilegi di root</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># su -</span></pre></div></div>

<p>controlliamo i parametri del nostro suexec:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /usr/lib/apache2/suexec -V</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_DOC_ROOT</span>=<span style="color: #ff0000;">&quot;/var/www&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_GID_MIN</span>=<span style="color: #000000;">100</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_HTTPD_USER</span>=<span style="color: #ff0000;">&quot;www-data&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_LOG_EXEC</span>=<span style="color: #ff0000;">&quot;/var/log/apache2/suexec.log&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_SAFE_PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/bin:/usr/bin:/bin&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_UID_MIN</span>=<span style="color: #000000;">100</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_USERDIR_SUFFIX</span>=<span style="color: #ff0000;">&quot;public_html&quot;</span></pre></div></div>

<p>come potete vedere dal risultato, i parametri cablati al momento della compilazione sono molti.<br />
spostiamoci in /usr/src e scarichiamo i sorgenti necessari al nostro scopo</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /usr/src</span>
<span style="color: #666666; font-style: italic;"># apt-get update</span>
<span style="color: #666666; font-style: italic;"># apt-get build-dep apache2</span>
<span style="color: #666666; font-style: italic;"># apt-get source apache2</span></pre></div></div>

<p>ok, adesso spostiamoci nella directory con i sorgenti e configuriamo apache con i parametri che ci interessano:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd apache2-2.2.3</span>
<span style="color: #666666; font-style: italic;"># nano debian/rules</span></pre></div></div>

<p>all&#8217;interno del file rules troverete un sacco di parametri. quelli ci interessano in questo momento sono quelli sotto la voce AP2_COMMON_CONFARGS.<br />
quindi modifichiamo quanto ci serve andando a cambiare quanto presente alla riga</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">      <span style="color: #660033;">--with-suexec-docroot</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hosting \</pre></div></div>

<p>e salviamo.<br />
ora, semplicemente, dovremmo ricompilare il file. prima di farlo però, è necessario modificare la versione di apache in modo tale che il nostro cambiamento non venga sovrascritto ad ogni upgrade.<br />
quindi</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># dch -i</span></pre></div></div>

<p>e ci troviamo all&#8217;interno del changelog di apache.<br />
UN CONSIGLIO: se non volete dover reinstallare tutti i pacchetti di apache, eliminate la versione che dch vi aggiunge in automatico e andate a lavorare sull&#8217;ultima. aggiungete un bel * e inserite il vostro commento, tipo: &#8220;fixed suexec docroot to: /home&#8221; e salvate.<br />
in questo modo la versione rimarrà inalterata e apache installerà solo la &#8220;patch&#8221; da voi applicata</p>
<p>a questo punto dobbiamo solo compilare e pacchettizzare</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># dpkg-buildpackage</span></pre></div></div>

<p>aspettate la fine delle operazioni di compilazione, tornate in /usr/src e installate i pacchetti modificati (nel nostro caso apache2.2-common e apache2.2-utils)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /usr/src //o se volete cd ../</span>
<span style="color: #666666; font-style: italic;"># dpkg -i apache2.2-common_2.2.3-4+etch6_amd64.deb </span>
<span style="color: #666666; font-style: italic;"># dpkg -i apache2-utils_2.2.3-4+etch6_amd64.deb</span></pre></div></div>

<p>fatto questo restartate apache, verificate che tutto sia andato a posto ed eventualmente controllate i conflitti con apt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/init.d/apache2 restart</span>
<span style="color: #666666; font-style: italic;"># /usr/lib/apache2/suexec -V</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_DOC_ROOT</span>=<span style="color: #ff0000;">&quot;/home&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_GID_MIN</span>=<span style="color: #000000;">100</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_HTTPD_USER</span>=<span style="color: #ff0000;">&quot;www-data&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_LOG_EXEC</span>=<span style="color: #ff0000;">&quot;/var/log/apache2/suexec.log&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_SAFE_PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/bin:/usr/bin:/bin&quot;</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_UID_MIN</span>=<span style="color: #000000;">100</span>
     <span style="color: #660033;">-D</span> <span style="color: #007800;">AP_USERDIR_SUFFIX</span>=<span style="color: #ff0000;">&quot;public_html&quot;</span> 
<span style="color: #666666; font-style: italic;"># apt-get install -f</span></pre></div></div>

<p>alla prossima!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ciarpame.com/2008/10/27/cambiare-facilmente-il-docroot-di-suexec-su-debian-sargelennyetch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE 6: header Content-disposition ignorati (ignored) !!FIXED!!</title>
		<link>http://www.ciarpame.com/2008/10/13/ie-6-header-content-disposition-ignorati-ignored-fixed/</link>
		<comments>http://www.ciarpame.com/2008/10/13/ie-6-header-content-disposition-ignorati-ignored-fixed/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 21:13:43 +0000</pubDate>
		<dc:creator>Daniele Veratti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.ciarpame.com/?p=179</guid>
		<description><![CDATA[Tra tutti i browser del mondo, quello che mi da più rotture è Internet Explorer. Ho smesso anche di usarlo, ma non per sentimenti di ribellione incondizionata e pinguinosa nei confronti di Microsoft, ma perché credo che Firefox sia meglio, soprattutto se di lavoro si fa lo sviluppatore web. Nonostante tutte però gli utenti usano [...]]]></description>
			<content:encoded><![CDATA[<p>Tra tutti i browser del mondo, quello che mi da più rotture è Internet Explorer. Ho smesso anche di usarlo, ma non per sentimenti di ribellione incondizionata e pinguinosa nei confronti di Microsoft, ma perché credo che Firefox sia meglio, soprattutto se di lavoro si fa lo sviluppatore web. Nonostante tutte però gli utenti usano IE, e parecchi ancora usano IE 6.<br />
<span id="more-179"></span></p>
<p>In particolare Internet Explorer 6 mi ha dato una bella gatta da pelare con i file da scaricare.<br />
In un&#8217;applicazione web che ho scritto è possibile scaricare alcuni file, solo da parte di utenti registrati. Quindi i file stanno fuori dalla visibilità del browser e vengono serviti da un file (download.php, nel mio caso) che, dopo aver fatto i relativi controlli a login e permessi vari, cambia gli header in modo da far scaricare il file scelto. Semplificando molto è una cosa simile:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> db<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
checkPermission<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'userid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM attachments WHERE id = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mime'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-disposition: attachment; filename=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Transfer-Enconding: binary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">@</span><span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'full_path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Risultato? Con Firefox nessun problema, con IE 7 nessun problema (eh meno male!!) ma con IE6&#8230; disastro!! I file venivano scaricato, ma IE6 ignorava bellamente l&#8217;header content-type e l&#8217;header content-disposition, nominando il file &#8220;download.php&#8221;.</p>
<p>Le ho provate davvero tutte per ovviare a questo problema, cambiare header rigurdanti la cache,ecc. ecc., ma l&#8217;unico effetto che sono riuscito ad ottenere è stato che il file non si chiamava più download.php, ma download.pdf piuttosto che download.zip&#8230;ma io voglio il nome corretto!!!</p>
<p>Google alla mano, ho fatto mille ricerche che non hanno portato a nulla finchè non sono arrivato a questa pagina: http://www.sitefoundry.com/broken_msie.html<br />
e qui ho appreso che per un baco, IE6 in questi casi tenta sempre due richieste andando in errore e che a differenza di Firefox utilizza il protocollo HTTP 1.1 anziché 1.0. Allora mi sono detto: &#8220;non è che è tutto un problema di protocollo?!?&#8221;.<br />
Prima di:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type ...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>ho inserito la seguente riga:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 200 OK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>forzando così che la mia risposta sia in HTTP/1.0&#8230;e ha funzionato!!!<br />
La mia spiegazione è questa: IE cerca (per motivi di sicurezza, dicono) di indentificare autonomamente il tipo di file, ignorando i Content-type e content-disposition vari che si mettono. Forzando il protocollo HTTP a 1.0 probabilmente IE si va a trovare in una modalità compatibile col vecchio protocollo, disabilitando le feature che normalmente utilizza col protocollo HTTP/1.1.</p>
<p>Bisogna stare attenti però all&#8217;output compression: il vostro server (Apache) potrebbe avere attivo mod_gzip, il che porterebbe a &#8220;g-zippare&#8221; tutto il suo output per risparmiare banda di rete. Purtroppo il &#8220;caro vecchio&#8221; IE6 ha un po&#8217; di problemi a trattare gli header con output gzipped.<br />
La soluzione è in questo caso aggiungere una riga</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">apache_setenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;no-gzip&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>al vostro script, prima di mandare in output il file da servire. Eventualmente verificate anche che sia disattivata la compressione gzip da PHP.<br />
Per disattivarla occorre aggiungere</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zlib.output_compression&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Io ci sono impazzito 2 giorni su sta cosa&#8230;spero che possa essere d&#8217;aiuto a molti! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ciarpame.com/2008/10/13/ie-6-header-content-disposition-ignorati-ignored-fixed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

