携帯サイトのDOCTYPE宣言についてで各キャリアごとにDOCTYPE宣言が異なるという記事を書きました。
ひとつのhtmlで携帯サイトを作り、
各キャリアからアクセスがあった場合、DOCTYPE宣言を切り替えるにはどうしたら良いか。
切り替えのPHPを紹介しますので、SSIは必須ですが利用してみてください。
XHTMLベースの紹介になります。(厳密に切り替える必要はないかもしれませんが。。。)
SSIをHTMLで読み出す場合、.htaccess等に
以下を追加し、PHPと同じディレクトリに置きます。
AddHandler server-parsed html
AddType application/xhtml+xml .html
AddType application/xhtml+xml .xhtm .xhtml
ユーザーエージェントの切り替え方法は、
携帯ホームページを作ろう! -ちょっと詳しいモバイルサイトの作り方-を参考にしています。
■こちらをそのままコピーするか、
以下ファイルをダウンロードするかになります。
doctype.txt[右クリック・ダウンロード]
(拡張子をphpに変更してください。)
完全フリーです。著作権もありません。改変もどんどんやっちゃってください。
2008年11月11日ちょい変更。preg_matchにて分岐することにしました。
<?php
$agent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match("/DoCoMo/", $agent)) {
print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n");
print
("<!DOCTYPE html PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">\n");
print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n");
print ("<head>\n");
print ("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=Shift_JIS\" />");
} elseif(preg_match("/KDDI\-/", $agent)||preg_match("/UP\.Browser/", $agent)) {
print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n");
print ("<!DOCTYPE html PUBLIC \"-//OPENWAVE//DTD XHTML 1.0//EN\" \"http://www.openwave.com/DTD/xhtml-basic.dtd\">\n");
print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n");
print ("<head>\n");
print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />");
} elseif(preg_match("/J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank/", $agent)) {
print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n");
print ("<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"xhtml-basic10-plus.dtd\">\n");
print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">\n");
print ("<head>\n");
print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />");
} else {
print("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\n");
print
("<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n");
print ("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\">\n");
print ("<head>\n");
print ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" />");
}
?>
■読み出しこちらをになります。任意のフォルダで良いと思います。
PHPの場所はトップディレクトリから相対パスで指定してください。
<!--#include virtual="/php/doctype.php"-->
■htmlソースはこんな感じでしょうか。
<!--#include virtual="/php/doctype.php"-->
<meta name="keywords" content="キーワード1,キーワード2" />
<meta name="description" content="サイトの紹介文" />
<title>サイトのタイトル</title>
</head>
<body>
本文
</body>
</html>
少しでもXHTMLベースの携帯サイトが増えることを祈っています。
CHTMLベースは捨てましょう。
絵文字変換、画像縮小変換、全角半角変換などとそれぞれに処理が必要になってくるので、
わたしは「Movable Type(MT)」と「ケータイキット for Movable Type」を利用することをおススメします。
※最近流行の特定の会社へリンクしているスパムではありません。
※ケータイキット for Movable Typeは携帯サイトの構築においてコストの面、機能的にも必要最低限用意されていて、自由度が高くわかりやすいからです。
shibaです。
先日は書き込みありがとうございました!
記事読みました。当ブログへのリンクありがとうございます。
ちょうど僕もSSIとPHPで作ろうかなぁと思っていたので、
ナイスタイミング!便利なスクリプトですね。
参考にさせていただきます。
それでは!
shibaさん
コメント有難うございます。
[Think IT]の執筆お疲れ様でした。
非常に参考になる内容でした。
携帯サイトがもっと盛り上がるよう頑張って行きましょう。
shibaさんを応援してます。
初めまして
拡張子がphpのページで、このスクリプトを使い、XHTMLと認識させるにはどうすればいいのでしょうか
拡張子がphpのページの一番上に、

を記入してアクセスしてみたのですが、XHTMLと認識されなかったためfont-sizeなどが適応されませんでした
接続環境:ドコモFOMA SH-04A
突然のご質問申し訳御座いません。
お返事頂けると幸いです。
どうぞよろしくお願い致します。
申し訳御座いません。
拡張子がphpのページの一番上に、
(A)
を記入してアクセスしてみたのですが、XHTMLと認識されなかったためfont-sizeなどが適応されませんでした
(A)の部分はdoctypeのスクリプトです。
記入したのですが、消えてしまいました。
申し訳御座いません。
toshiさん、コメント有難うございます。
PHPの場合ですが、ユーザーエージェントの切り替えは
出来ているでしょうか。各キャリアでアクセスしたときにDOCTYPE宣言が変わっていれば
PHPは正常に動いています。確認するときはシュミレーター等を利用すといいと思います。
PHPの場合はさらに、HTTPヘッダでMIMEタイプを指定すれば問題ないかと思います。
header("Content-type: application/xhtml+xml");
それと.htaccessで以下を追加すれば問題ないかと思います。
AddType application/x-httpd-php .xhtml
Kamitani79様
お返事有り難う御座います。
ご指摘頂いた、
header("Content-type: application/xhtml+xml");
を書くとXHTMLと認識されました!
有り難う御座いました^^
Expert seo, pro en marketing et programmeur web de compétence, Mr Sotton augmente les visites de vos sites internet et prend à sa charge le netlinking en mode black hat ou white par
rapport à votre budget. Consultez le site de ce consultant search engine optimization :
https://www.nicolas-sotton.ch/consultant-seo/
Hi colleagues, its wonderful post regarding teachingand entirely explained, keep it up all the time.
Tremendous issues here. I am very glad to see your article.
Thanks a lot and I'm looking forward to touch you. Will you kindly drop me
a e-mail?
No matter if some one searches for his vital thing, thus he/she needs to be available that in detail, thus that thing is maintained over here.
If you would like to take a great deal from this paragraph then you have to apply these strategies
to your won webpage.
My partner and I absolutely love your blog and find nearly all of your post's to be exactly
what I'm looking for. Do you offer guest writers to write
content in your case? I wouldn't mind composing a post
or elaborating on many of the subjects you write concerning here.
Again, awesome web site!
L'entreposage de vos affaires ont des avantages certains :
cela donne la possibilité de veiller ses meubles en toute confiance dans un box propice et propre.
Tout l'équipement : chariots, transpalettes,... est mis à disposition
검증사이트, 먹튀검증 먹튀사이트 먹튀검증사이트 먹튀폴리스입니다.
먹튀폴리스 먹튀검증커뮤니티는 신규는
물론 오픈된 먹튀사이트를 철저히 검증하여 먹튀없는 시대를
만들어가고 있습니다. 먹튀검증 먹튀폴리스를 사랑하는 여러분의 많은 호응바랍니다.
여러분의 충실한 먹튀검증 사이트가 되도록 노력하겠습니다.
Pretty! This has been an incredibly wonderful post.
Thank you for supplying this info.
Ohvera Polka Dot Red Black Lace Dress Women Hollow Out
A-line Mini Summer Dress Elegant High Waist Sexy Party Dresses Vestidos …
Shipping
For newest information you have to pay a quick visit internet and on the web I found
this website as a most excellent website for most recent updates.
Hiya! Quick question that's totally off topic. Do you know how to make your site mobile friendly?
My site looks weird when viewing from my apple
iphone. I'm trying to find a template or plugin that might be able to fix this problem.
If you have any recommendations, please share.
Thanks!
How To Get Girls On Omegle
The landing page is come into making you money. Gone are the days where any links
were good enough to achieve good page ranks with serps.
Your success will involve a regarding work a number of time.
With havin so much written content do you ever run into any problems of plagorism
or copyright infringement? My site has a lot of exclusive content I've
either written myself or outsourced but it seems a lot of it
is popping it up all over the internet without my permission. Do you know any ways to help stop content
from being stolen? I'd really appreciate it.
May I just say what a comfort to discover somebody that actually understands what they're talking about on the
web. You actually realize how to bring an issue to light and make it important.
A lot more people have to check this out and understand this side of your story.
I was surprised you are not more popular since you surely have the
gift.
I always emailed this weblog post page to all my associates, because if like to read it then my
friends will too.
I am sure this article has touched all the internet
people, its really really pleasant paragraph on building up new webpage.
Good site you have here.. It's difficult to find high quality writing like yours
nowadays. I seriously appreciate individuals like
you! Take care!!
Wow, fantastic blog layout! How long have you ever been running a blog for?
you made blogging glance easy. The overall look of your site is magnificent, as smartly as the content
material!
Hi there, of course this article is truly fastidious and I have learned lot of things from it about blogging.
thanks.