Smartyのtpl側でセッションの値が参照できない - PHPプロ!Q&A掲示板
PHP側で$_SESSION['hoge']は参照できるのに、Smartyの.tpl側で{$smarty.session.hoge}が参照できません。
環境
さくらレンタルサーバ
FreeBSD 7.1-RELEASE-p8 i386
Apache/1.3.42 (Unix)
PHP 5.2.12
Smarty 2.6.25
どなたかご教授ください。お願いします。
施してみたこと
セッションIDを手動でsesにしてみた(変化なし)
コンパイル済みのテンプレートファイルを削除して再生成(変化なし)
mod_rewriteを疑い、rewriteが無関係なページでsessionのテスト(ここでも参照出来ず)
php.iniを確認。(文字エンコやインクルードパスの設定のみなので思い当たる所なし。)
処理の流れとしては、
1.login.phpで認証処理、認証できればセッションに名前などを格納。
2./tr/homeへリダイレクト
3.メニューを表示
です
- require("smarty/Smarty.class.php");
- require("MDB2.php");
- class MySmarty extends Smarty{
- private $_db;
- public function __construct(){
- $this->Smarty();
- $this->template_dir="~~php/smarty/templates/";
- $this->compile_dir="~~php/smarty/templates_c/";
- $this->config_dir="~~php/smarty/config/";
- $this->config_load("config.conf",basename($_SERVER['SCRIPT_NAME'],".php"));
- $this->caching=2;
- $this->cache_dir="~~php/smarty/cache/";
- $this->cache_lifetime=60*15;
- //$this->security=False;
- $dsn=array("phptype"=>"***","username"=>"***","password"=>"***","hostspec"=>"***","database"=>"***");
- $this->_db=MDB2::connect($dsn);
- $this->_db->query("SET NAMES utf8");
- }
- public function __destruct(){
- $this->_db->disconnect();
- }
- public function getDb(){
- return $this->_db;
- }
- }
- //login.php
- //~~略~~
- if($mb->getObject()->isDoCoMo()){ //docomoならばTrue
- ini_set('session.auto_start', 0);
- ini_set("session.use_cookies",0);
- ini_set("session.use_trans_sid",1);
- ini_set("session.name", "ses");
- if(isset( $_GET['ses'])){
- $sessionId = $_GET['ses'];
- session_id($sessionId);
- }
- }
- //~~略~~
- session_start();
- $_SESSION['name'] = $data['name'];
- if($mb->getObject()->isDoCoMo()){ //端末がdocomoならTrue
- header("Location: /tr/home?guid=ON&".session_name()."=".strip_tags(session_id()));
- }else{
- header("Location: /tr/home?guid=ON");
- }
- //home.tpl
- {include file="mobile/common/header.tpl"}
- {$smarty.session.name}さんのマイページ //null
- <hr>
- <ol style="padding:0 5px;">
- <li><a href="/tr/gps?guid=ON" accesskey="1">メニュー1</a></li>
- <li><a href="/tr/friend?guid=ON" accesskey="2">メニュー2</a></li>
- <br />
- <li><a href="/tr/logout?guid=ON">ログアウト</a></li>
- </ol>
- <hr>
- {include file="mobile/common/footer.tpl"}
この質問への意見の募集は締め切られ、ポイントは既に配分されました。
意見を投稿することはできますが、ポイントを受け取ることはできません。





ページのトップへ


SQLインジェクション対策は時と場合で使う関数が変わります。その時にあったものを使いましょう。