2012-10-13 1 views
1

구현했습니다. Secure login script입니다. 모두 괜찮습니다. 기사 편집을위한 내 페이지가 세션 또는 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'); 
    } 
    } 
?> 

답변

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.  
}