<?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>ものぐさ備忘録 &#187; http</title>
	<atom:link href="http://www.ginriki.net/wd/category/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ginriki.net/wd</link>
	<description>ソフトウェア関係の話を中心とした備忘録的日記</description>
	<lastBuildDate>Sun, 16 Jan 2011 20:07:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FlashPlayer10で外部swfのロードに失敗する件</title>
		<link>http://www.ginriki.net/wd/2008/11/05/46/</link>
		<comments>http://www.ginriki.net/wd/2008/11/05/46/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 07:25:15 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=46</guid>
		<description><![CDATA[2008/10にFlashPlayer10が正式リリースされました。
Flashの動作に若干変更が加えられたようで、バイト先のWebサイトで今まで正常動作していたFlashがFlashPlayer10では動かないという問 [...]]]></description>
			<content:encoded><![CDATA[<p>2008/10にFlashPlayer10が<a href='http://www.itmedia.co.jp/news/articles/0810/15/news067.html'>正式リリース</a>されました。</p>
<p>Flashの動作に若干変更が加えられたようで、バイト先のWebサイトで今まで正常動作していたFlashがFlashPlayer10では動かないという問題が起きました。</p>
<p>挙動を調べてみると、MovieClipLoader.loadClipで外部swfのロードに失敗してます。</p>
<p>外部swfとして指定するURLは実際にはPHPファイルを指しており、GETパラメータを変えることで<br />
PHPファイルが出力するswfデータが変わるようになってます。</p>
<p>どうも、PHPファイルがswfデータを出力する際に指定してるHTTPレスポンスヘッダが良くないようなので、調べてみるとContent-disposition 指定がswfロードに失敗する原因でした。</p>
<p>そこで、下記のようにContent-dispositionの指定をコメントアウトしたら、FlashPlayer10でも<br />
外部swfのロードに成功しました。</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#FF9933; font-style:italic;">//...略</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#FF9933; font-style:italic;">// header(&quot;Content-disposition: attachment;filename=&quot; . $filename);</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-type: application/x-shockwave-flash"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-length: "</span> . <a href="http://www.php.net/filesize"><span style="color:#000066;">filesize</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$filepath</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/readfile"><span style="color:#000066;">readfile</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$filepath</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Content-dispositionの仕様はRFCで規定されています。その内容については、<a href='http://www.studyinghttp.net/header#Content-Disposition'>こちら</a>によくまとめられています。<br />
以下、一部引用</p>
<pre>
Content-Disposition レスポンスヘッダフィールドは、ユーザがその内容を
ファイルに保存したい場合にオリジンサーバが既定のファイル名を提案する事を
意味するように勧告されている。
</pre>
<p>Adobe的には、Flashでロードするswfコンテンツに、ファイルを保存する場合に指定するフィールドを指定するなってことなんでしょうかねえ。</p>
<h4>その他FlashPlayer10の問題</h4>
<p>FlashPlayer10になって、バージョン番号が１桁から２桁に増えたため、<br />
バージョンチェックを適当に行うJavascriptを書いているサイトなどでは、<br />
FlashPlayer10をFlashPlayer1と勘違いして、Flashが表示されない問題が起きてるようです。<br />
<a href='http://bakera.jp/ebi/topic/3302'>http://bakera.jp/ebi/topic/3302</a></p>
<p>・・・なんとなく２０００年問題を思い出しました。</p>
<h4>追記</h4>
<p>Adobe公式の<a href='http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head32'>FlashPlayer10におけるセキュリティ上の変更点解説</a>の中で、<br />
Content-Disposition: attachment 指定されたswfに対する挙動を変えた理由が書いてありました。</p>
<p>不特定の人がファイルをアップロード/ダウンロードできるアップローダサイト等で、<br />
信頼できないユーザによってアップロードされたswfが、そのサイトドメイン上で実行される危険性を<br />
なくすためだそうです。</p>
<p>画像やxmlファイルなどは、Content-Disposition: attachmentがHTMLレスポンスヘッダに<br />
ついていても、今までと同様に動作するそうです。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/11/05/46/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ブラウザキャッシュの無効/有効</title>
		<link>http://www.ginriki.net/wd/2008/07/14/8/</link>
		<comments>http://www.ginriki.net/wd/2008/07/14/8/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 16:50:28 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=8</guid>
		<description><![CDATA[ブラウザキャッシュは意識して設定しないと簡単に無効になったり有効になったりしてしまいます。
必ず無効にしたい or 必ず有効にしたいというポリシーがあるなら、きちんとした設定が必要です。
・ブラウザキャッシュを]]></description>
			<content:encoded><![CDATA[<p>ブラウザキャッシュは意識して設定しないと簡単に無効になったり有効になったりしてしまいます。<br />
必ず無効にしたい or 必ず有効にしたいというポリシーがあるなら、きちんとした設定が必要です。</p>
<p><strong>・ブラウザキャッシュを無効する方法</strong><br />
<a href="http://blog.knockoutmarch.com/2008/02/06/2323.html">http://blog.knockoutmarch.com/2008/02/06/2323.html</a><br />
より引用</p>
<div class="igBar"><span id="lhtml-5"><a href="#" onclick="javascript:showPlainTxt('html-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-5">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- メタタグに以下を記述。 --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Pragma"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-cache"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Cache-Control"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-store"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Cache-Control"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-cache"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"-1"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- また、body内に以下を記述。 (for safari) --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/iframe.html"><span style="color: #000000; font-weight: bold;">&lt;iframe</span></a> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"height:0px;width:0px;visibility:hidden"</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"about:blank"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; this frame prevents back forward cache</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iframe&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>・ブラウザキャッシュを有効にする方法</strong></p>
<p>そもそも、あるリンクをクリックした後のブラウザキャッシュ挙動には2パターンあることに注意<br />
1. キャッシュしてあるコンテンツが新しくなっていないかwebサーバに問い合わせる。新しくなってなければキャッシュを使う。 (Last-Modified &#038; If-Modified-Since &#038; 304 status)</p>
<p>2. webサーバに問い合わせず、キャッシュをそのまま使う (Expires or Cache-Control: max-age)</p>
<p>しかも、ブラウザによってhttpレスポンス/リクエストヘッダのLast-Modified, Expiresなどの解釈や優先順位が違うことに注意。<br />
<a href="http://labs.cybozu.co.jp/blog/kazuho/archives/2006/02/utilizing_cache.php">http://labs.cybozu.co.jp/blog/kazuho/archives/2006/02/utilizing_cache.php</a><br />
<a href="http://fdays.blogspot.com/2007/11/ie6cache-controlcache.html">http://fdays.blogspot.com/2007/11/ie6cache-controlcache.html</a></p>
<p>以上を踏まえると、PHPコンテンツに対して、ブラウザキャッシュを上記2番の方法で一定時間有効にしたいときは下記のようにしとけば良さそう ( $interval 秒だけキャッシュを有効にしたいとする）</p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Expires: "</span> . <a href="http://www.php.net/gmdate"><span style="color:#000066;">gmdate</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"D, d M Y H:i:s"</span>, <a href="http://www.php.net/time"><span style="color:#000066;">time</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color:#0000FF;">$interval</span> <span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">" GMT"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Cache-Control: max-age="</span> . <span style="color:#0000FF;">$interval</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Pragma: cache"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// no-cache以外にすればＯＫ </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>キャッシュを無効にしたい場合も、有効にしたい場合も、同じようなhttpリクエスト項目を複数指定する必要があるのがだるい・・・</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/07/14/8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

