• 締切済み

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

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
  • 回答数1
  • ありがとう数2

みんなの回答

  • masa6272
  • ベストアンサー率66% (93/140)
回答No.1

最初の2つですが、session_start()の前にHTMLが送られているという意味です。session_start()はすべての出力の前に処理する必要があります。空白、改行1文字でも送っていたら、session_start()は動作しません。 ファイルの先頭 改行 <?php session_start(); でも、だめです。ファイルの先頭の改行が出力されています。 次のエラーは文字通りlogin.tplがないか、読めないと言うことです。Windowsのようですので、アクセス権の問題ではないでしょう。 テンプレートの名前が違うか、置く場所が間違っています。template_dirで指定した所に置いてあります?

seter777
質問者

補足

確認してみましたが、<?phpの前に改行も空白もありませんでした。 参考までにlogin.phpのプログラムを載せておきます。 <?php require('Smarty.class.php'); require('Login.class.php'); session_start(); $smarty = new Smarty; $login = new Login; if(empty($_SESSION["form1"])){ $_SESSION["form1"] = "input"; }else{ $login->checkPassword(); } $smarty->assign('pagetitle','ログイン画面'); $smarty->assign('errormsg',$login->errormsg); $smarty->assign('user', $login->user); $smarty->assign('passwd', $login->pass); if("checked" != $_SESSION["form1"]){ $smarty->display('login.tpl'); }else{ $_SESSION["user"] = "$login->user"; $smarty->display('welcome.tpl'); } ?> よろしくお願いします。

関連するQ&A

  • セッションとヘッダーの順序について

    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
  • headers already sent と言われてしまう。

    [portal.php] で、 <?php require ('Smarty.class.php'); require ('Plan.class.php'); session_start(); $smarty = new Smarty; $schedule = new Plan; if(empty($_SESSION["user"])){ Header("Location: login.php"); } 以下略 というコードを打って、実行したら Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\*******\Plan.class.php:122) in C:\Program Files\Apache Group\*******\portal.php on line 4 というエラーが出ます。 \Plan.class.php には <?php class Plan{ function __construct(){ $this->Zaikofile="C:Program Files\Apache Group\Apache2\logs\plan.sqlite"; $this->user=$_SESSION["user"]; $this->errorm=""; 以下略 ?>    ←122行目(最終行)です。 となっています。両方のプログラムとも、「<?php」の上の行には何も書いていません。 なぜ、headers already sentとなるのでしょうか? エラーの原因はどこにあるでしょうか?

    • ベストアンサー
    • PHP
  • smartyテンプレート読み込みについて

    Smarty動的Webサイト構築入門という書籍を見ながらSmartyを学習しているのですが、書籍のCD-ROMから落としたサンプルファイルを保存しているのですがどうしてもテンプレートを読み込むことができません。 03_01.php <?php require_once("../smarty/libs/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir = "templates"; $smarty->compile_dir = "templates_c"; $smarty->assign("name", "Smartyさん"); $smarty->display("03_01.tpl"); ?> 03_01.tpl Hello, {$name}!! エラーメッセージ Warning: Smarty error: unable to read resource: "03_01.tpl" in C:\xampp\htdocs\smartybook\smarty\libs\Smarty.class.php on line 1092 03_01.phpは、C:\xampp/htdocs/smartybook/ren/に保存しています。 03_01.tplは、C:\xampp/htdocs/smartybook/templates/に保存しています。 どこが駄目なのか教えてください。 宜しくお願いします。

    • 締切済み
    • PHP
  • phpのプログラムエラー

    とあるサイトを参考にして、 excelファイルをダウンロードできるようにしたいと思い記述しましたが、 エラーが出て困っています。 どのように修正すればよいか、アドバイスいただけないでしょうか? php初心者のため、初歩的な質問かもしれませんこと、お許しください。 windows7を利用しています。 ■表示されたエラーの内容 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\phpkiso\download.php:9) in C:\xampp\htdocs\phpkiso\download.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\phpkiso\download.php:9) in C:\xampp\htdocs\phpkiso\download.php on line 17 Warning: readfile(依頼書ダミー.xls) [function.readfile]: failed to open stream: No such file or directory in C:\xampp\htdocs\phpkiso\download.php on line 19 ■プログラム <?php // ダウンロードさせるファイル名 $tmp_file = "依頼書ダミー.xls"; $j_file = "依頼書.xls"; $j_file = mb_convert_encoding($j_file, "SJIS", "EUC"); // ヘッダ header("Content-Type: application/octet-stream"); // ダイアログボックスに表示するファイル名 header("Content-Disposition: attachment; filename=$j_file"); // 対象ファイルを出力する。 readfile($tmp_file); exit; ?>

  • 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
  • PHPエラー

    こんにちは。 初めてPHPでプログラミングをしている者です。 PHPのエラー解決方法で悩んでいます。 エラーの内容は Warning: session_start(): Cannot send session cookie - headers already sent by (output started at ~~) in ~~ Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at ~~)in ~~~ です。 お時間のある方回答お待ちしています。

    • ベストアンサー
    • PHP
  • utf8保存をするとsession_start()でエラーが出ます。

    PHP:バージョン 5.1.6 セッションを使ってログイン情報を保持したいのですが、 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Eclipse\workspace\ShopSystem\login.php:1) in C:\Eclipse\workspace\ShopSystem\login.php on line 2 と言うエラー情報が出てしまいます。 セッションが既に開始されているらしいのですが、他にセッションスタートを記述した場所がありません。 プログラムの文字コードをutf8にするとこのようになってしまうのですが、shift-JISやutf8nでは正常に動作します。 自力で思いつける解決作は文字コードを全部変えてしまうことなのですが、できればutf8で作りたいと思っています。 お願い致します。 プログラム <?php session_start();  //ログインページ require('config.php'); if($_POST['keep_login']!=''){     session_set_cookie_params(31536000);//31536000(1年間の秒数)=365(日)*24(時間)*3600(秒) }else{     session_set_cookie_params(0); } *略 ?> <html>

    • ベストアンサー
    • 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
  • いつもお世話になっております。

    いつもお世話になっております。 小生、只今WindowsXPSP3上でXAMPP1.7.1を使用し、PHPを勉強しているPHP初心者です。 今回皆様にご質問させて頂きたい内容はXAMPPにSmatyをインストールするべきかしないべきかです。 私の環境でXAMPPのフォルダ内で「smarty」というキーワードを入れ、検索してみたところ、以下のファイルが検出されました。 smarty ディレクトリ     C:\xampp\htdocs\xoops\class Smarty.class.php       C:\xampp\htdocs\xoops\class\smarty Smarty_Compiler.class.php   C:\xampp\htdocs\xoops\class\smarty Smarty-2.6.0 ディレクトリ  C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor core.assign_smarty_interface.php C:\xampp\htdocs\xoops\class\smarty\core core.smarty_include_php.php  C:\xampp\htdocs\xoops\class\smarty\core SmartyTask.php C:\xampp\php\PEAR\phing\tasks\ext smarty ディレクトリ C:\xampp\htdocs\extras\extra_languages\pt_utf8\html\class Smarty ディレクトリ C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Converters\HTML Smarty.class.php C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Smarty-2.6.0\libs Smarty_Compiler.class.php C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Smarty-2.6.0\libs HTMLSmartyConverter.inc C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Converters\HTML\Smarty core.assign_smarty_interface.php C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Smarty-2.6.0\libs\core core.smarty_include_php.php C:\xampp\php\PEAR\PhpDocumentor\phpDocumentor\Smarty-2.6.0\libs\core 以上のファイルがあっても、XAMPPにSmartyをインストールしなければ、Smartyの機能は使えないのでしょうか?? また、上記の設定(Smartyをインストールしていない状態)でC:\xampp\sample\templatesフォルダを作成し、以下の.tplファイルを作成しました。 -----.tplファイル------ <html> <head> <title>smatyのテスト</title> </head> <body> ようこそ、($name)さん<br/> Hello World! </body> </html> そしてその上位フォルダにindex.phpを作成しました。 -----index.php----- <?php require_once "Smarty.class.php"; $smarty = new Smarty; $smarty->assign('name', '桃太郎'); $smarty->;display('index.tpl'); ?> 上記の2ファイルを作成し、http://localhost/sampleにアクセスしても、 「Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in C:\xampp\htdocs\sample\index.php on line 6」のエラーが出現し、正確に表示されません。 お忙しい中、大変申し訳ございませんが、先輩方アドバイス宜しくお願い致します。

    • ベストアンサー
    • PHP
  • PHP のsetcookie()関数について

    PHP5を使ったHTML文書で、setcookie()関数を使っていますが、以下のようなメッセージが出てきてクッキーに新しいデータを書き込むことが出来ません。 環境はWindows10, IE11です。 PHP使用方法: $fname="mondai10.txt" setcookie("filename", $fname);  // line 38 setcookie("version",3); // line 39 メッセージ: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\QAmondaiDisplay.php:3) in C:\xampp\htdocs\QAmondaiDisplay.php on line 38 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\QAmondaiDisplay.php:3) in C:\xampp\htdocs\QAmondaiDisplay.php on line 39 そしてこのクッキーを次のようにJavaScriptで読み込んでいるのですが、表示させてみると書き込んだものとは全く異なるものが表示されます。 JavaSript 使用法: var cookiedata = window.document.cookie; window.document.getElementById("q1").innerHTML =cookiedata;; 実際に表示されるもの: PHPSESSID=57c35633ffc2fe44622ee27e61bf44eb; filename=yasudaShiroexpires=Mon, 08 Oct 2018 21:44:48 GMT そしてこの表示は、最後の時間以外はいつも同じです。 どこに問題があるのでしょうか? 詳しい方、どうか教えてください。

    • ベストアンサー
    • PHP

専門家に質問してみよう