ZendFrameworlkでZend_Sessionが使えません

このQ&Aのポイント
  • ZendFrameworlkでZend_Sessionが正常に動作せず、エラーが発生しています。
  • ローカル環境の設定が問題の可能性がありますが、具体的にどのような箇所を見ればよいでしょうか。
  • 環境はWindowsVista、Apache 2.2.6、PHP 5.2.4(xampp)、ZendFramework1.0.3です。
回答を見る
  • ベストアンサー

ZendFrameworlkでZend_Sessionがつかえません

表題の通り、Zend_Sessionが使えません。 $session = new Zend_Session_Namespace('global'); と記述すると、下のエラーがでます。インスタンスを生成する部分を除けば 正常に動作し、他のZendFrameworlkコンポーネントは使える状態です。同じソースでもレンタルサーバ上では思い通りに動くので私のローカル環境の設定がおかしいと思うのですが、何を見たらいいでしょうか。 環境はWindowsVista、Apache 2.2.6、PHP 5.2.4(xampp)、ZendFramework1.0.3です。 Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in C:\xampp\htdocs\index.php/1' in C:\xampp\ZendFramework\library\Zend\Session.php:359 Stack trace: #0 C:\xampp\ZendFramework\library\Zend\Session\Namespace.php(116): Zend_Session::start(true) #1 C:\xampp\htdocs\index.php(22): Zend_Session_Namespace->__construct('global') #2 {main} thrown in C:\xampp\ZendFramework\library\Zend\Session.php on line 359

  • PHP
  • 回答数1
  • ありがとう数1

質問者が選んだベストアンサー

  • ベストアンサー
  • tany180sx
  • ベストアンサー率63% (239/379)
回答No.1

if (headers_sent()) {  throw new Zend_Session_Exception(上記error_msg); } となっているので、HTTPヘッダが既に送信されているのが原因かと。 レンタルサーバで大丈夫なのは、output_bufferingが有効になっているからじゃないでしょうか。 ローカルでも動くように処理の順番を変えたほうがよいのでは?

jackmkh
質問者

お礼

早速の回答ありがとうございます。 教えていただいたoutput_bufferingをレンタルサーバと同じ、「4096」にすることで、動作するようになりました。  また、処理内容も検討してみようと思います。  ありがとうございました。

関連するQ&A

  • zendのcontrollersについて

    Zendを始めたばかりのものです。 サーバ:XPで自営 Apache2,php5 Zendをダウンロードし、Cドライブのルートに「ZendFramework-1.9.0」 という名前で配置しました。 php.iniのinclude_pathの設定も変更し、 htdocsの直下にindex.phpを作成し <?php require_once 'Zend/Version.php'; //ライブラリの読み込み echo Zend_Version::VERSION; //現在のZend Frameworkのバージョンを表示 とすると、正常にバージョンが表示されます。 zendappsというフォルダーをhtdocsの中に作成し、index.phpに <?php require_once 'Zend/Controller/Front.php'; Zend_Controller_Front::run('../zendapps/controllers'); とするとエラーになります。(エラーは長いので後述) '../zendapps/controllers'の部分かとも思いますが、 お分かりになる方、教えていただけると幸いです。 エラーの内容 Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\ZendFramework-1.9.0\library\Zend\Controller\Dispatcher\Standard.php:242 Stack trace: #0 C:\ZendFramework-1.9.0\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\ZendFramework-1.9.0\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch() #2 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\zendapps\index.php(3): Zend_Controller_Front::run('../zendapps/con...') #3 {main} thrown in C:\ZendFramework-1.9.0\library\Zend\Controller\Dispatcher\Standard.php on line 242

    • ベストアンサー
    • PHP
  • セッションとヘッダーの順序について

    session_name("WebID"); session_start(); を header("Content-Type: text/html; charset=UTF-8"); のあとに呼び出すとエラーになります。 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\php\index.php:56) in C:\xampp\htdocs\php\verify.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\php\index.php:56) in C:\xampp\htdocs\php\verify.php on line 3 やはりセッションを先に呼び出さないといけないのでしょうか? session_unsetというものを使えばこの順序でもうまくいきますか? index.phpからエラーが起きたファイルを表示させているので、 順序は変えにくいのですが、順序を変えなくてもクリアできる 方法があったら教えてください。

    • ベストアンサー
    • PHP
  • ZendFramework-1.0.2の環境設定

    IndexController.php以外の Controllerファイルが起動いたしません。 以下のようなエラーが出力されます。どのように対処したらよいでしょうか。よろしくお願いいたします。 Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\zend\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php:194 Stack trace: #0 C:\zend\ZendFramework\library\Zend\Controller\Front.php(920): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\zend\ZendFramework\library\Zend\Controller\Front.php(224): Zend_Controller_Front->dispatch() #2 C:\Apache Group\Apache2.2\htdocs\zdb1\index.php(10): Zend_Controller_Front::run('./application/c...') #3 {main} thrown in C:\zend\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php on line 194

    • ベストアンサー
    • PHP
  • ZendFramework 環境設定

    現在、Zendframeworkで開発していこうと考えていたんですが、以下のエラーがでて先に進めません。本来は「http://localhost」とアクセスすると画面が表示されるはずなのですがダメです。 環境[OS X] サーバー[Xampp for mac] Warning: require_once(Zend/Controller/Front.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 2 Fatal error: require_once(): Failed opening required 'Zend/Controller/Front.php' (include_path='.:/php/includes:/Applications/XAMPP/ZendFramework/library/Zend') in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 2

    • 締切済み
    • PHP
  • 会員管理システムを作っているのですが、エラーが出て困っています。

    phpとsmartyで会員管理システムを構築しているのですが、以下のようなエラーが出て困っています。 エラー文 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Login.class.php:1) in C:\xampp\htdocs\login.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Login.class.php:1) in C:\xampp\htdocs\login.php on line 5 Warning: Smarty error: unable to read resource: "login.tpl" in C:\xampp\htdocs\Smarty.class.php on line 1092 このエラー文は何と言っているのですか? また、解決方法が分かる方、ご回答お願いします。

    • 締切済み
    • PHP
  • Zend Frameworkでoracle接続

    Zend Frameworkを勉強しようと思い始めたばかりのものです。 oracleに繋がらずどこをチェックすればよいのかさっぱりわかりません。 どなたかご教授願えないでしょうか? zfツールを使い雛形を作って、module で分けてみたり、ヘッダー、フッターをlayoutを使って分けたりと少し前進しました。 次はDB接続だと思い始めたのですが繋がりません。 ■環境 CentOS release 5.6 (Final) ■やったこと 1)oracle接続モジュール oci8 をインストール # export ORACLE_HOME=/opt/oracle/product/10.2.0/db # pecl install oci8 php.ini に追記 # vi /etc/php.ini extension=oci8.so 2)ローカルで接続テスト これは問題なく接続できてるみたいなのです。 # more test.php <?php putenv("ORACLE_HOME=/opt/oracle/product/10.2.0/db"); putenv("LD_LIBRARY_PATH=:/opt/oracle/product/10.2.0/db/lib"); // Zend_Dbライブラリの読み込み require_once 'Zend/Loader.php'; require_once 'Zend/Db.php'; $dbInit = array( 'host' => 'localhost', 'username' => 'usrxx', 'password' => 'usrxx', 'dbname' => 'xxdb' ); $db = Zend_Db::factory('oracle', $dbInit); $db->getConnection(); echo 'OK'; $db->closeConnection(); # php test.php OK 3)Zend Frameworkで接続テスト IndexController.php の indexAction でやってみたのですがダメなのです。 public function indexAction() { $dbInit = array( 'host' => 'localhost', 'username' => 'usrxx', 'password' => 'usrxx', 'dbname' => 'xxdb' ); $db = Zend_Db::factory('oracle', $dbInit); $db->getConnection(); $db->getConnection(); echo 'OK'; $db->closeConnection(); } ※/etc/sysconfig/httpdに以下を追加しました export ORACLE_HOME=/opt/oracle/product/10.2.0/db export LD_LIBRARY_PATH=/opt/oracle/product/10.2.0/db/lib 実行するとどうしてもエラーとなります。 ■エラーメッセージ An error occurred Application error Exception information: Message: Unknown exception Stack trace: #0 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Db/Adapter/Abstract.php(315): Zend_Db_Adapter_Oracle->_connect() #1 /home/www/zf/application/modules/default/controllers/IndexController.php(30): Zend_Db_Adapter_Abstract->getConnection() #2 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Controller/Action.php(516): IndexController->indexAction() #3 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction') #4 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #6 /home/www/zf/venders/ZendFramework-1.11.11/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #7 /home/www/htdocs/shopping/necs/zf/index.php(29): Zend_Application->run() #8 {main} Request Parameters: array ( 'controller' => 'index', 'action' => 'index', 'module' => 'default', ) どこを確認すればよいかのサッパリわからず投稿させていただきました。 何卒よろしくお願いします。

    • 締切済み
    • PHP
  • session_start()を使うと警告メッセージが出ます。

    PHP4.2.2、apche1.3.27、VineLinux2.6を使っています。 PHPで、session_start()を使うと以下のような警告メッセージが出てしまいます。何かphp.ini内に、セッティングしないといけないことが あるのでしょうか? [ブラウザに表示されたメッセージ] Warning: Cannot send session cookie - headers already sent by (output started at /usr/local/apache/htdocs/a/a02.php:10) in /usr/local/apache/htdocs/a/a02.php on line 12 Warning: Cannot send session cache limiter - headers already sent (output started at /usr/local/apache/htdocs/a/a02.php:10) in /usr/local/apache/htdocs/a/a02.php on line 12 10 + 200 = 210 [実行したスクリプト] <html> <head> <title>aaa</title> </head> <body bgcolor="red"> <?php session_cache_limiter('private'); session_start(); $a = 10; $b = 200; $c = $a + $b; print("$a + $b = $c"); ?> </body> </html>

    • ベストアンサー
    • PHP
  • Zend Frameworkが機能しなくて

    困っています。 Fedora11にZendFrameworkをDLして解凍して /usr/local/ZendFramework-1.9.3PL1 として入れました。 /etc/php.ini: ......... include_path = ".:/usr/local/ZendFramework-1.9.3PL1/library" ......... と設定し /etc/httpd/conf/httpd.conf: ......... LoadModule rewrite_module modules/mod_rewrite.so ......... <Directory "/var/www/html/zend/public"> AllowOverride All </Directory> と設定し /var/www/html/zend/public/.htacess: RewriteEngine on RewriteBase / RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php と設定し /var/www/html/zend/public/index.php: <?php require_once 'Zend/Version.php'; echo Zend_Version::VERSION; とし #service httpd restart とアパッチを実行し Firefoxブラウザのアドレス欄に http://localhost/index.php を入力しアクセスしたところブラウザに Not Found The requested URL /index.php was not found on this server. Apache/2.2.13 (Fedora) Server at localhost Port 80 と404エラーがでます。 ちなみに http://localhost/zend/public/index.php にアクセスすれば 1.9.3PL1 が問題なく表示されます。 しかしこれではZendフレームワークでWebアプリを組めません。 どうすれば解決できるでしょうか?

    • ベストアンサー
    • PHP
  • セッション管理に関する質問

    レンタルサーバで、セッションを使ったアクセスカウンターを書いているのですが(管理人のアクセスで、カウンタが回らない様に) ↓のような警告が出ました 「Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/httpd/maagairu/public_html/index.php:7) in /home/httpd/maagairu/public_html/index.php on line 7」 「Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/httpd/maagairu/public_html/index.php:7) in /home/httpd/maagairu/public_html/index.php on line 7」 これは、「キャッシュが送れない」「クッキーを送れない」、という意味だと思うのですが、これは私のブラウザの設定の問題でしょうか。 この警告の解決方法を教えてください

    • ベストアンサー
    • PHP
  • $obj->varの変数のアクセスの仕方。

    php5で、 $objMyClass = new MyClass(); $objMyClass->var // varは任意で、実際は何でもよい。 print_r($objMyClass); として見たら、varという変数が$objMyClassに定義されているようなのですが、この変数へのアクセスをどうやったらいいのかわかりません。 教えてください。 と、言いますのは、zendFrameWorkでは、 http://framework.zend.com/manual/ja/zend.session.basic_usage.html $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $authNamespace->user = "myusername"; とすると、 $_SESSION['Zend_Auth']['user'] = "myusername"; と同じ結果になるようなのです。 これは"user"を、Zend_Session_Namespaceクラス内で、 $_SESSION['Zend_Auth']の後ろにくっつけて多次元配列化しているんですよね? これと同じ実装をしたいと思っています。 もしかして何か勘違いしてますでしょうか?

    • ベストアンサー
    • PHP

専門家に質問してみよう