PHPをHTMLソースに組み込み

[新着] Webテンプレートを仮オープンしました



0   名前: X-plate : 2007/04/22(日) 15:53  ID:FdrzQQEJ sub-Ds
みなさんこんにちは

某参考書のサンプルスクプリトを改造して
会員管理システムをPHPで作成しているのですが

HTMLとPHPの混合がうまくいかず
原因もよくわからない状態となっています

次のように
上のほうにPHPソース、下のほうにHTMLタグ(ホームページNInja8で作成)を設置すると
エラーがでませんが・・・


account.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('title', 'X-plate Account');
$smarty->assign('error', $login->errorm);
$smarty->assign('id',    $login->id);
$smarty->assign('passwd',$login->pass);

if("checked" != $_SESSION["form1"]){
	$smarty->display('login.tpl');
}else{
	$_SESSION["user"]="$login->id";
	$smarty->display('welcome.tpl');
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML lang="ja">

<!--2007/03/31 15:24:59-->

<HEAD>
  <META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
  <META http-equiv="Content-Style-Type" content="text/css">
  <META http-equiv="Content-Script-Type" content="text/javascript">
  <META name="keywords" content="X-plate,バーチャルワールド,仮想世界">
  <META name="description" content="X-plate はチャットサービスをはじめとする3Dバーチャルワールドを提供しています">
  <META name="GENERATOR" content="ホームページNinja 8 for Windows Product Version 8.0.0">
  <LINK rel="Shortcut Icon" href="img001.ico">
  <TITLE>X-plate Account</TITLE>
<STYLE type="text/css">
<!--
BODY {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
TABLE {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
TD {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
DIV {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
SPAN {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
-->
</STYLE>
</HEAD>
           〜省略〜
</HTML>

このように
PHPソースを下または真ん中にいれると・・・

account.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML lang="ja">

<!--2007/03/31 15:24:59-->

<HEAD>
  <META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
  <META http-equiv="Content-Style-Type" content="text/css">
  <META http-equiv="Content-Script-Type" content="text/javascript">
  <META name="keywords" content="X-plate,バーチャルワールド,仮想世界">
  <META name="description" content="X-plate はチャットサービスをはじめとする3Dバーチャルワールドを提供しています">
  <META name="GENERATOR" content="ホームページNinja 8 for Windows Product Version 8.0.0">
  <LINK rel="Shortcut Icon" href="img001.ico">
  <TITLE>X-plate Account</TITLE>
<STYLE type="text/css">
<!--
BODY {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
TABLE {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
TD {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
DIV {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
SPAN {
  font-family: "MS Pゴシック";
  font-size: 12pt;
}
-->
</STYLE>
</HEAD>
           〜省略〜
</HTML>

<?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('title', 'X-plate Account');
$smarty->assign('error', $login->errorm);
$smarty->assign('id',    $login->id);
$smarty->assign('passwd',$login->pass);

if("checked" != $_SESSION["form1"]){
	$smarty->display('login.tpl');
}else{
	$_SESSION["user"]="$login->id";
	$smarty->display('welcome.tpl');
}

?>

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Apache Group\Apache2\htdocs\chap6\account.php:12) in C:\Apache Group\Apache2\htdocs\chap6\account.php on line 228

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Apache Group\Apache2\htdocs\chap6\account.php:12) in C:\Apache Group\Apache2\htdocs\chap6\account.php on line 228

というようなエラーが出てしまいます

これを直すにはどうしたらいいのでしょうか
長くなってしまいましたがよろしくお願いします


1   名前: 匿名 : 2007/04/22(日) 15:53  ID:drXsP5it sub-.G
http://www.php.gr.jp/
のプロジェクト/マニュアル日本語化のV.機能を読んで下さい。

2   名前: X-plate : 2007/04/22(日) 15:53  ID:FdrzQQEJ sub-Ds
解決しました

一覧へ戻る