• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:Smartyを使用した、テンプレート内でのキャリア振り分け)

テンプレート内でのキャリア振り分けについて

xyz951の回答

  • xyz951
  • ベストアンサー率18% (15/79)
回答No.2

PEARのNet_UserAgent_Mobile使えばいい。 ついでにテンプレートでこんな表示方式の変更をする? キャリアごとにテンプレート作って呼び出すテンプレートを 変えた方がいいと思うけど

ideal16
質問者

お礼

御返答ありがとうございます。 さっそくPEARの方を調べてみます。 基本的に3キャリア対応でコーディングしているので、分けたいのはごく一部なんですよ。。 その場合はsmartyでちょこっと書いた方が楽ですね。

ideal16
質問者

補足

ざっくり見てみましたが、おおよそ上のプログラムと変わらないようです。 smartyとの繋ぎがうまくいかないようです。

関連するQ&A

  • phpでエージェントの振り分けがうまくいかない

    phpでエージェントの振り分けがうまくいかない 以下のようにmフォルダの中にindex.phpを以下の内容で設置し、同列でi,a,sフォルダを設け それぞれindex.htmlを設けました。しかし携帯でhttp://hoge.com/m で打つとサイトがみつかりませんになります。<?phpより上は空白、改行はありません。 振り分けがうまく機能しないのはなぜでしょうか? <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://hoge.com/m/i/index.html"); exit; }else if(preg_match("/^(J?-PHONE|Vodafone|MOT?-[CV]|SoftBank)/i", $agent)){ header("Location: http://hoge.com/m/s/index.html"); exit; }else if(preg_match("/^KDDI?-/i", $agent) || preg_match("/UP?.Browser/i", $agent)){ header("Location: http://hoge.com/m/a/index.html"); exit; }else{ header("Location: http://hoge.com/index.php"); exit; } ?>

    • ベストアンサー
    • PHP
  • 携帯とPCの振り分け

    同じドメインにて携帯とPCの振り分けなのですが、htaccessにて振り分けたのですが、ブラウザに「振り分けがループしています」とでるのですが、 これはなぜでしょう? htaccessの中身の内容ですが、 DirectoryIndex index.php index.html index.htm これで読み込んだindex.phpの中身は <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: http://www.○○○○○.com/mobile/index.xhtml"); exit; }else{ header("Location: http://www.○○○○○.com/"); exit; } ?> サーバはlolipopでhtaccessのパーミッションは604で phpのパーミッションは700です。

    • 締切済み
    • CGI
  • 携帯、スマートフォンのPHP振り分け

    こんなPHPを書いているのですが どうしてもParse errorが出ます。 解決方法を教えて下さい!! ■エラー内容 Parse error: syntax error, unexpected T_EXIT in /home/sites/heteml/users/web/m/index.php on line 5 ■振り分けPHP <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: ​http://www.hogehoge.com/m/i/index.html");​ exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: ​www.hogehoge.com/m/s/index.html");​ exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: ​www.hogehoge.com/m/e/index.html");​ exit(); }else if(preg_match("iPhoneやスマートフォン用の判定", $agent)){ header("Location: www.hogehoge.com/m/smt/index.html"); exit(); }else{ header("Location: ​www.hogehoge.com/m/pc/index.html");​ exit(); } ?> よろしくお願い致します。

    • ベストアンサー
    • PHP
  • i Phone 用振り分け

    以下のように携帯キャリアごとに振り分け、3キャリア以外は PCフォルダに振り分けるようにした場合ですが、PCフォルダの方で i Phone 用に幅480pxで作成したページを配置すると PCから http://mypage.net/ でアクセスしたユーザーにも i Phone 用の幅480pxページを見せるようになってしまいますか? i Phoneやスマートフォンの対処はどうされているんでしょうか? <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://mypage.net/i/index.html"); exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: http://mypage.net/s/index.html"); exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: http://mypage.net/e/index.html"); exit; }else{ header("Location: http://mypage.net/pc/index.html"); exit; } ?>

    • ベストアンサー
    • PHP
  • 携帯ユーザーのPHPによる振り分け

    WindowsXP dreamweaverCS3を使用 PHPの知識はまったくありません。 PCサイト「www.deri6mon.com」(PC用サイト)がすでにできており、 これをQRコードに変換してあります。 そのQRコードをユーザーがスマホと携帯のバーコードリーダーで変換し、 PCサイトにアクセスさせますが、携帯ユーザーは当然容量がオーバーしますので エラーでとまってしまいます。 そこで、別に携帯サイトを用意してPCサイトにアクセスしてきた携帯ユーザーを 携帯サイトに自動で振り分けたいと考えています。 PCサイトの最上部に下記を記述しました。 PHPを書き込んだファイルはhtml→phpに拡張子を変換してあります。 -----------------ここから------------------- <?php $page_m='http://www.deri6mon.com/mb/index.html'; $agent=$_SERVER['HTTP_USER_AGENT']; if (preg_match("/UP\.Browser\/[3-5]/",$agent) || preg_match("/J-PHONE\//",$agent) || preg_match("/DoCoMo\//",$agent) && !(preg_match("/(Win|Mac|Linux|FreeBSD|OS¥/2|Solaris)/i",$agent)) || preg_match("/UP.Browser/",$agent) || preg_match("/^Vodafone/",$agent) || preg_match("/^SoftBank/",$agent) || preg_match("/^MOT-/",$agent) || preg_match("/DDIPOCKET;/",$agent) || preg_match("/WILLCOM;/",$agent) || preg_match("/L-mode\/\//",$agent)) { header("Location: $page_m"); }else{ }//end if ?> -----------------ここまで---------------- しかしどうしても携帯でPCサイトが表示されてしまいます。 どこの設定(記述)をどうしたら良いのでしょうか。 因みにhttp://emu.mobile.goo.ne.jp/emu/emu.phpでPCサイトのアドレスを入れると携帯サイトのTESTが表示されるので記述は問題ないと思います。 教えてgooの過去Qを調べてみて気がついた記述が、私が使っているサーバーは 自動で挿入される広告があり「header Locationはエラーになる」というのが ありました。 これを回避するにはどうすればいいのでしょうか? PHPの知識が無いのでわかりやすく回答していただけるとたすかります。 よろしくお願いいたします。

    • ベストアンサー
    • PHP
  • ユーザーエージェントの振り分け

    すみません、エージェント振り分けで以下のようにPHPファイルを作りました。 そして各ホルダ i,s にindex.htmlを配置したところ Warning:Cannot modify header information headers already sent by (output started at /home/lolipop,jp-dp44253830/web/mobile/index.php:1) in/home/sites/lolipop.jp/users/lolipop.jp-dp44253830/web/mobile/index.php on line 4 index.php <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://homepege.net/mobile/i/index.html"); exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: http://homepage.net/mobile/s/index.html"); exit; 省略 } ?> お手数ですが教えてください。

    • ベストアンサー
    • PHP
  • サイトが移動しました(301)が出てしまいます。

    以下のようにキャリア判別しましたが、ドコモ(f706i) でみるとサイトが移動しました(301)が出ます。 これはなんとかならないんでしょうか? <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: ​http://sample.com/i/index.html");​ exit; }else if(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]|SoftBank)/i", $agent)){ header("Location: ​http://sample.com/s/index.html");​ exit; }else if(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){ header("Location: ​http://sample.com/e/index.html");​ exit; }else{ header("Location: ​http://sample.com/pc/index.html");​ exit; } ?>

    • ベストアンサー
    • PHP
  • 【PHP・.htaccess】PCと携帯の振り分けについて

    【PHP・.htaccess】PCと携帯の振り分けについて お世話になります。 PHP・.htaccess共に初心者なのですが、 PCサイトと携帯サイトの振り分けで悩んでいるので宜しくお願い致します。 現在の構成が http://sample.com/ ←トップページ(PHPファイルのみ。各トップへ振り分け) http://sample.com/pc/ ←PCトップページ http://sample.com/mo/ ←モバイルトップページ(.htaccessでIP制限。PCからのアクセスはトップへ) ---------------------------------------------------- 振り分けPHP(http://sample.com/) <?php $agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/^DoCoMo/i", $agent)){ header("Location: http://sample/mo/"); exit; }else if(preg_match("/^(J-PHONE|Vodafone|MOT-[CV]|SoftBank)/i", $agent)){ header("Location: http://sample/mo/"); exit; }else if(preg_match("/^KDDI-/i", $agent) || preg_match("/UP.Browser/i", $agent)){ header("Location: http://sample/mo/"); exit; }else{ header("Location: http://sample/pc/"); exit; } ---------------------------------------------------- となって居ますが、都合により http://sample.com/ ←PCトップ モバイルからのアクセスはmoに振り分け。 http://sample.com/mo/ ←モバイルトップページ。(.htaccessでIP制限。PCからのアクセスはトップへ) 上記の形に切り替えたいと思っています、 PHPを使って振り分けをしたいと思っているのですが、 上記の形を再現する事は出来ますでしょうか? また、.htaccessを利用する事により解決が出来るのであれば、 そちらもご教授いただけると幸いです。

    • 締切済み
    • PHP
  • キャリア判別

    キャリア判別するため見よう見まねで以下の通りindex.phpを作成しまして、i,e,sのフォルダにそれぞれindex.htmlを入れまいが、真白で 何も映りません、なぜでしょうか?教えてください。 <?php $ua = $_SERVER['HTTP_USER_AGENT']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN"><HEAD> <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP"> <meta http-equiv="Content-Language" content="ja"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="cache-control" content="max-age=0"> <META name="keyword" content=""> <META name="description" content=""> <META name="robots"content="index,follow"> </HEAD> <body> <?php switch(TRUE){ case preg_match("/^DoCoMo\/2\.0/i", $ua): case preg_match("/^DoCoMo\/1\.0/i", $ua): $carrier = "i"; break; case preg_match("/^SoftBank/i", $ua): case preg_match("/^J\-PHONE/i", $ua): case preg_match("/^Vodafone/i", $ua): case preg_match("/^MOT/i", $ua): $carrier = "s"; break; case preg_match("/^KDDI\-/i", $ua): case preg_match("/^UP.Browser/i", $ua): $carrier = "e"; break; default: $carrier = "pc"; break; } $html_filename = "index.html"; $html_filepath = "templates/" .carriers. "/" .$html_filename; $output = @file_get_contents($html_filepath); echo $output; ?> </body> </html>

    • ベストアンサー
    • PHP
  • SMARTYのエラーについて。について。

    今度業務でPHPをやる事になったので手始めにSmartyを使って簡単なアプリケーションを作ってみようと思ったのですが、最初の段階でいきなりつまづいてしましました。 具体的には、サンプルサイトからコピーした以下の様なphp&テンプレートを動かすと決まって次のエラーになります。 【/var/www/html/test/index.php】 <?php require_once('/var/www/smarty/libs/Smarty.class.php'); $smarty = new Smarty; $smarty->assign('name', 'test'); $smarty->display('index.tpl'); ?> 【/var/www/html/test/templates/index.tpl】 <html> <head> <title>User Info</title> </head> <body> 名前:{$name}<br> </body> 【エラー】 Warning: preg_match() [function.preg-match]: Compilation failed: repeated subpattern is too long at offset 18454 in /var/www/smarty/libs/Smarty_Compiler.class.php on line 454 ちなみに環境は以下の通りです。 OS:CentOS5.2 web:apache2.2.3 php:5.1.6 Smarty:2.6.21 同様の基本的なサンプルを他にもいくつか実行しましたが、結果は上記エラーと全く同一のものしか出力されません… 同じ症状が出て対応された方がいらっしゃいましたら回答の程よろしくお願い致します。

    • ベストアンサー
    • PHP