PHP4.3.9+smartyのsessionについて

このQ&Aのポイント
  • PHPでログイン画面・入力画面・登録を作るためのsessionの使い方について
  • sessionをクッキーを使わずに利用する方法について
  • smartyを使用したsessionの表示方法について
回答を見る
  • ベストアンサー

PHP4.3.9+smartyのsessionについて

お世話になります。 PHPで、ログイン画面・入力画面・登録を作りたいと思ってます。 手始めにsessionをクッキーを使わずに使用したいと思い簡単に作ってみました。 login.phpの記述(ログイン) $smarty=new SubSmarty; session_start(); $_session[] $_session["id"]='abcde'; $smarty->display("insert.tpl"); nyuryoku.tpl <html> <head> </head> <body> {$smarty.session.id} </body> <html> この時点でsessionの中身が見れません。 よろしくお願いします。

  • kou99
  • お礼率35% (23/65)
  • PHP
  • 回答数1
  • ありがとう数0

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

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

session_start(); $_SESSION['id'] = 'abcde'; これで動きますか?

関連するQ&A

  • session_startについて

    初心者です。 以下のように、ログイン時、設定画面adminpage.htmlに行くように作っています。 sakuraインターネットでは動くのですが、 もう一方の違うサーバーでは、login.phpに戻ってきてしまいます。 原因が判りません。 手がかりが欲しいのですが、 お詳しい方がおられましたら教えてください。 よろしくお願い致します。 <?php require("MySmarty.class.php"); require('Settings.class.php'); $smarty = new MySmarty(); $settings = new Settings; session_start(); $id = $_SESSION['id']; $pass = $_SESSION['pass']; //idとパスワードに不具合有れば、login.phpへ戻る。 if( ( $id == '' ) || ( !$settings->isValidUser($id,$pass) ) ){ header("Location: login.php" ); print $_SESSION["id"]; print $_SESSION["pass"]; print $id; print $pass; exit; } $settings->loadSettings(); $smarty->assign('maintitle', $settings->maintitle); $smarty->assign('subtitle', $settings->subtitle); $smarty->assign('error_message', $settings->errorm); $smarty->display('adminpage.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
  • Smartyについて

    Smartyについて Smartyをインストールしました。 OS:ubuntu インストール先:/usr/local/lib/Smarty-2.6.26 php.ini[include_path]の設定:/usr/local/lib/Smarty-2.6.26/libs/を追加 /var/www/以下にtestフォルダ作成 /var/www/test/index.html | /test/index.php chmod 644 | /tempalates chmod 775 templates | / index.tpl chmod 644 /templates_c chmod 775 templates_c /configs chmod 775 configs /cache chmod 775 cache index.phpの内容 <?php require_once(”Smarty.class.php"); $o_smarty=new Smarty(); $o_smarty->template_dir="./templates/"; $o_smarty->compile_dir="./template_c/"; $o_smarty->assign("name","world"); $o_smarty->display("hello.tpl"); ?> index.tplの内容 <html> <head> <title>Hello,world</title> </head> <body> Hello,{$name}! </body> </html> http://web.domain/test/index.php を入力するとエラーは出ませんが、何も表示されません。 これだけで、原因を特定出来ないのかもしれませんが、何処が悪いのでしょうか? 御教示お願いいたします。

  • PHP+smartyで困っております。

    今までASPで開発をおこなっておりましたが、PHPを勉強中のPHP初心者です。 さて、smartyでの表示ですがどうしてもうまくいきません。 $smarty->assign("info",manage::getinfo(18,$a_db)); $smarty->display("comp_regist2.tpl"); で、smartyを利用したいのですが、値が表示されません。 {debug} にて下記値がわたされているのは確認しております。 Array (1) 0 => manage Object (2) _id => 18 _company_name => AAA店 tplファイルに、下記内容を記入してみましたが、表示されません。 {$info._id|escape}<hr> {$info._company_name|escape}<hr> {$_id}<hr> {$_company_name}<hr> {debug} {$info._id} {$info._company_name} 丸二日、、、こんなところではまっております。 お教えいただけませんでしょうか?

    • ベストアンサー
    • PHP
  • Smartyについて教えてください。

    Smartyについて教えてください。 参考書によってテンプレートの存在するディレクトリを指定している場合(1)と していない場合(2)がありますが、 どちらが正しいのでしょうか? (1) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = "template02/"; $smarty->compile_dir = "compile/"; $smarty->display("content.tpl"); ********************************************* (2) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->display("content.tpl"); *********************************************

    • ベストアンサー
    • PHP
  • PHPのセッションについて

    PHPのセッションについて 現在ログインフォームを作成しているのですが、 ログインフォームからIDとパスワードを送信して、合っていれば セッションを発行してロケーションで飛ばそうと思っているのですが、 初回時にIDとパスワードを入力して送信しても、セッションが引き継がれず 2回目以降だとセッションが引き継がれる症状に悩んでおります。 どなたかご教授ください。 宜しくお願いいたします。 【login.php】-------------------------------- <?php session_name("stock"); session_start(); $error_flag = 0; if(isset($_POST["login"])){ $id = htmlentities($_POST["id"],ENT_COMPAT); $password = trim(htmlentities($_POST["password"],ENT_COMPAT)); if($login_id == $id && $login_pass == $password){ $_SESSION["id"] = $id; $_SESSION["password"] = $password; header("Location:stock.php"); exit; }else{ $error_flag = 1; } } echo <<<EOD <form method="post" action="login.php" id="login"> <input type="text" name="id" id="id" > <input type="password" name="password" id="password"> <input type="submit" name="login" value="ログイン" /> </form> EOD; 【stock.php】--------------------------------- <?php session_name("stock"); session_start(); echo $_SESSION["id"]; echo $_SESSION["password"]; ?>

    • ベストアンサー
    • PHP
  • PHP Smartyについて質問です。

    レイアウトファイル(main.tpl)にタグを配置し そのタグをあるデータに置換したいと考えています。 例えば、以下のような感じです。 ~~~ main.tpl ~~~~~~~~~~~~~~~~ <html> <body> <div id="header">ヘッダー</div> <div id="nav">ナビゲーション</div> <div id="contents">#CONTENTS#</div> <div id="footer">フッター</div> </body> </html> ~~~~~~~~~~~~~~~~~~~~~~~ 上記の「#CONTENTS#」の部分をDBで保存している コンテンツに置換したいのですが {if}構文や{$hoge}などのSmartyタグが文字列として出力されてしまいます。 何か無理やりDBのデータをSmartyのコンパイラに通すメソッド等ありませんでしょうか? もしくは、他のやり方で何かいい方法はありませんでしょうか? DBで保存している部分をtplファイルにして、$smarty->fetch("fuga.tpl"); 等で読みだせば 解決するんですが、どうしてもこのコンテンツ部分はtplファイルにはせず DBから直接コンパイルしたいのです。 どなたかご教授くださいませ。 よろしくお願いいたします。

    • ベストアンサー
    • PHP
  • Smartyに関しまして

    require_once("Smarty/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir = "./templates"; $smarty->compile_dir = "./templates_c"; $smarty->assign("message", "こんばんは"); $a = array('hello','php','html'); $smarty->assign('a',$a); $smarty->display("index.tpl"); これでindex.tplで出力すると日本語部分が「?????」になってしまいます。 何か設定がいるんでしょうか??

    • ベストアンサー
    • PHP
  • PHPとSmartyを使い、データベースからのデータを表示したい。

    PHP・Smartyを使い、DBからの表示を行おうとしています。 基本的な作業だとは思うのですが、なかなかできないので、教えてください。 ソースコードです。 //////PHPのコード <?php require_once('Connections/dbconn_mylocal.php'); ?>//DBへの接続を行っている。ここは正常。 <?php $sql = 'SELECT * FROM c_movie'; $result = mysql_query($sql, $conn); while($row = mysql_fetch_array ($result)){ $movie = $row["movie_title"]; } $smarty->assign('movie', $movie); $smarty->display("test1120.tpl"); ?> /////////////////tplファイル <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Smartyで表示する</title> </head> <body> ({foreach item='con' from=$movie}) ({$con}) ({/foreach}) </body> </html> よろしくお願いします!

    • ベストアンサー
    • PHP
  • smartyについて

    smartyについて 環境は、windows /php-5 / smarty-2.6.17です。 以下の2つエラーが出てどう対処すればいいか困っています。 【1つめ】 Fatal error: Smarty error: [in **.tpl line 10]: syntax error: unrecognized tag: 文--> 【2つめ】 {$errmsg (Smarty_Compiler.class.php, line 446) in C:\xampp\php\PEAR\Smarty\libs\Smarty.class.php on line 1095 【ソース】 呼び先PGは、 $this->smarty->assign("errmsg","ニックネーム"); $this->smarty->display("**.tpl"); テンプレートでは、 <tr id="" class=""> <td id="" class=""><font color="#ff0000">{$errmsg}を入力してください。</font></td> </tr> よろしくお願いいたします。

    • 締切済み
    • PHP

専門家に質問してみよう