1

この安全なログイン スクリプトを実装しました。すべて問題ありませんが、記事編集用のページがセッションまたは sth を中断します。したがって、このページにアクセスした場合は動作していますが、このページから出た場合はログアウトされます。「改ページ」のコードは次のとおりです。

<?php
  include "includes/db_connect.php";
  include "includes/functions.php";
  sec_session_start();
  $page = $_SERVER['REQUEST_URI'];
  if(login_check($mysqli) == true) {
    include "includes/admin-header.php";
    $dotaz = new mysqli(HOST, USER, PASSWORD, DATABASE);
    if(empty($_GET['id'])){
      $stmt_articles = $dotaz->prepare("SELECT id, title, text FROM articles ORDER BY id DESC LIMIT 1");
      $stmt_articles->execute();
      $stmt_articles->store_result();
      $stmt_articles->bind_result($id_article, $title, $text);
      $stmt_articles->fetch();
    } else {
      $id=$_GET['id'];
      if($stmt_articles = $dotaz->prepare("SELECT id, title, text FROM articles WHERE id = ? LIMIT 1")) { 
      $stmt_articles->bind_param('i', $id);
      $stmt_articles->execute();
      $stmt_articles->store_result();
      $stmt_articles->bind_result($id_article, $title, $text);
      $stmt_articles->fetch();
      }
    } 
?>
  <div id='editation'>
    <div class='edit-title'>
      EDITACE: <a href="#" class='active'>ČLÁNKY</a> / <a href="#">NASTAVENÍ</a> <a href="#">NÁHLED</a>
    </div>
    <div class='edit-submenu'>
      <?php
        $dotaz2 = new mysqli(HOST, USER, PASSWORD, DATABASE);
        if($stmt_vypis = $dotaz2->prepare("SELECT id, title, text FROM articles ORDER BY id DESC LIMIT 0,8")) { 
          //do prepare se imho pouzije limit ?,? a pak se to bude bindovat pokazde jinymi cisly pro scrollovani?
          //$stmt_articles->bind_param('i', $id);
          $stmt_vypis->execute();
          $stmt_vypis->store_result();
          $stmt_vypis->bind_result($id_a, $titulek, $s_text);
          while($stmt_vypis->fetch()){
            echo "<a class='item' href=\"clanky.php?id=".$id_a."\">
                    <img src=\"http://25.media.tumblr.com/avatar_6feb8634e3d0_128.png\"/>
                    <p class='item-title'>".substr($titulek, 0, 20)."</p>
                    <p class='item-author'>Admin</p>
                    <div>
                      <p class='item-teaser'>".substr(strip_tags($s_text), 0, 20)."</p>
                      <p class='item-time'>Před 2 dny</p>
                    </div>
                </a>";            
          }
        }
      ?>
    </div>
    <script type="text/javascript">
      $(document).ready(function(){
        $(".edit-submenu").niceScroll({cursorcolor:"rgba(0, 0, 0, 0.6)"});
      });
    </script>
    <form action="clanky.php" method="post">
      <input type="text" size="80" name="title" value="<?php echo "$title"; ?>" />
      <textarea name="text" cols="100" rows="30"><?php echo "$text"; ?></textarea>
    </form>
  </div>
<?php
    include "includes/admin-footer.php";
  } else {
    if(!headers_sent()){
      header('Location: ./index.php?error=1');
    }
  }
?>
4

1 に答える 1

0

関数 sec_session_start() を編集し、session_set_cookie_params() のドメインを明示的に指定する必要がありました。

function sec_session_start() {
    $domain = 'example.com'; // note $domain
    $session_name = 'sec_session_id'; // Set a custom session name
    $secure = true; // Set to true if using https.
    $httponly = true; // This stops javascript being able to access the session id. 
    ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. 
    $cookieParams = session_get_cookie_params(); // Gets current cookies params.
    session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $domain, $secure, $httponly); // note $domain
    session_name($session_name); // Sets the session name to the one set above.
    session_start(); // Start the php session
    session_regenerate_id(true); // regenerated the session, delete the old one.     
}
于 2013-04-23T20:55:53.807 に答える