1

주제: session_start 함수를 rewrite.php 에 넣고싶은데...

rewrite.php // 소스...

<? session_start(); ?>
<?php
    define('ROOT', '.');
    /* Workaround for IIS environment */
    if(!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME'])) {
        $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
        if(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
    }
    if (!empty($_SERVER['PRELOAD_CONFIG']) && file_exists('config.php')) require_once ROOT."/config.php";
        /* Retrieve Access Parameter Information. */
    $accessInfo = array(
        'host'     => $_SERVER['HTTP_HOST'],
        'fullpath' => str_replace('index.php', '', $_SERVER["REQUEST_URI"]),
        'position' => $_SERVER["SCRIPT_NAME"],
        'root'     => rtrim(str_replace('rewrite.php', '', $_SERVER["SCRIPT_NAME"]), 'index.php')
        );
    if (strpos($accessInfo['fullpath'],$accessInfo['root']) !== 0)
        $accessInfo['fullpath'] = $accessInfo['root'].substr($accessInfo['fullpath'], strlen($accessInfo['root']) - 1);
    // Workaround for compartibility with fastCGI / Other environment
    $accessInfo['input'] = ltrim(substr($accessInfo['fullpath'],
        strlen($accessInfo['root']) + (defined('__TEXTCUBE_NO_FANCY_URL__') ? 1 : 0)),'/');
    // Support Tattertools 0.9x legacy address (for upgrade users)
    if (array_key_exists('pl', $_GET) && strval(intval($_GET['pl'])) == $_GET['pl']) { header("Location: ".$accessInfo['root'].$_GET['pl']); exit;}
    $part = strtok($accessInfo['input'], '/');
    if (in_array($part, array('image','plugins','script','cache','skin','style','attach','thumbnail'))) {
        $part = ltrim(rtrim($part == 'thumbnail' ?
              preg_replace('/thumbnail/', 'cache/thumbnail', $accessInfo['input'], 1) :
              $accessInfo['input']), '/');
        if(file_exists($part)) {
            require_once ROOT.'/lib/function/file.php';
            dumpWithEtag($part);
            exit;
        } else {
            header("HTTP/1.0 404 Not Found");exit;
        }
    }
    if (strtok($part, '?') == 'setup.php') {require 'setup.php'; exit;}
    $accessInfo['URLfragment'] = explode('/',strtok($accessInfo['input'],'?'));
    unset($part);
    @session_start();
    /* Check the existence of config.php (whether installed or not) */
    if (!file_exists('config.php')) {
        if (file_exists('.htaccess')) {print "<html><body>Remove '.htaccess' file first!</body></html>";exit;}
        print "<html><body><a id='setup' href='".rtrim($_SERVER["REQUEST_URI"],"/")."/setup.php'>Click to setup.</a></body></html>";exit;
    }
    /* Determine that which interface should be loaded. */
    require_once 'config.php';
    if(defined('__TEXTCUBE_NO_FANCY_URL__')) $service['type'] = 'single';
    switch ($service['type']) {
        case 'path': // For path-based multi blog.
            array_splice($accessInfo['URLfragment'],0,1);
            $pathPart = ltrim(rtrim(strtok(strstr($accessInfo['input'],'/'), '?'), '/'), '/');
            break;
        case 'single':
            $pathPart = (strpos($accessInfo['input'],'?') !== 0 ? ltrim(rtrim(strtok($accessInfo['input'], '?'), '/'), '/') : '');
            break;
        case 'domain': default:
            $pathPart = ltrim(rtrim(strtok($accessInfo['fullpath'], '?'), '/'), '/');
            if(!empty($service['path'])) $pathPart = ltrim($pathPart,$service['path']);
            break;
    }
    $pathPart = strtok($pathPart,'&');
    /* Load interface. */
    $interfacePath = null;
    if (in_array($pathPart, array('favicon.ico','index.gif'))) {require_once 'interface/'.$pathPart.'.php';    exit;}
    if (!empty($accessInfo['URLfragment']) &&
        in_array($accessInfo['URLfragment'][0],
                 array('api','archive','attachment','author','category','checkup','cover','cron','entry','feeder','foaf','guestbook','keylog','location','logout','notice','page','plugin','pluginForOwner','search','suggest','sync','tag','ttxml')))
    {
        $pathPart = $accessInfo['URLfragment'][0];
        $interfacePath = 'interface/blog/'.$pathPart.'.php';
    } else if (is_numeric(strtok(end($accessInfo['URLfragment']), '&'))) {
        $pathPart = count($accessInfo['URLfragment'])==1 ? null : implode('/', array_slice($accessInfo['URLfragment'], 0, count($accessInfo['URLfragment']) - 1));
    }
    if (empty($interfacePath)) $interfacePath = 'interface/'.(empty($pathPart) ? '' : $pathPart.'/').'index.php';
    define('PATH', 'interface/'.(empty($pathPart) ? '' : $pathPart.'/'));
    unset($pathPart);
    if (!file_exists($interfacePath)) { require "lib/error.php";errorExit(404);}
    if (empty($service['debugmode'])) {    @include_once $interfacePath;}
    else {include_once $interfacePath;}
?>

맨윗줄에, 절대 변수 세션 <? session_start(); ?> 을 넣으니깐, 제가만든 인증세션은 작동하는데,

텍스터큐브 의 관리자 로그인이나, 메뉴 하이퍼링크를 클릭하면, 기능들이 죽어버립니다. 안된다는거죠...

<? session_start(); ?> 을 넣고싶은데, 어데다가 넣으면 좋을까요?

세션 절대함수를 넣으니깐, 로그인페이지에서 로그인이 안되네요...

2

답글: session_start 함수를 rewrite.php 에 넣고싶은데...

너무 과감하게 말씀하시는거같으시네요 ㅜㅜ

3

답글: session_start 함수를 rewrite.php 에 넣고싶은데...

^^; 조금 과감하셨습니다. creorix님.. wink

궁극적으로 원하시는 기능이 다른 기능과의 세션 변수 연동인가요?
세션관리에 대한 것은
http://dev.textcube.org/wiki/SessionManagement
링크를 참조하시고 연동에 대한 좀더 구체적인 것을 얘기해주시면 다른 방향으로 가이드를 만들어 보겠습니다.

4

답글: session_start 함수를 rewrite.php 에 넣고싶은데...

음, 질문을 한데 모아놓으니 이제서야 무엇을 하시려는 건지 대충 알 것 같군요..;; 기왕이면 질문을 올려주실 때 포럼의 특성(?)을 활용해서 첫 쓰레드에 계속 추가하는 식으로 올려주시면 한 눈에 의도 파악도 되고 좋을 것 같네요.
(그러고보니 질문답변 포럼은 '게시판'처럼 운영하고 있군요..음-_-)

그러니까 하시려는 게 블로그를 보려면 인증 절차를 한 단계 두고 싶다는 것인데, 그 인증 절차가 굳이 매우 특별한 형식이 아닌 이상 텍스트큐브 자체의 블로그 공개 설정 기능을 이용하시는 것이 가장 나을 것 같습니다. 만약 예전에 올리셨던 질문 중에 pass.php를 반드시 써야 한다면 거기서 인증 결과를 해시 등으로 생성해서 쿠키로 구우신 다음 텍스트큐브의 rewrite.php 같은 곳에서 체크하면 되지 않을까요?

예를 들면 pass.php에서 통과가 되면 key를 생성하고 그 key를 DB에 저장 + 쿠키로 설정한 다음 텍스트큐브로 redirect 시켜서 rewrite.php에서 해당 key와 DB에 저장이 된 게 일치하는지 확인한다든지 말이죠. 좀더 안전하게 하려면 timestamp를 넣어 시간 제한을 하거나 무한히 key가 쌓이는 걸 방지할 수도 있겠구요. (그러니까 php에서 하는 session 관리를 간단하게 직접 구현하는 것도 한 방법이라는 얘깁니다. 말씀하신 상황으로 봐선 php 자체의 세션 관리와 텍스트큐브의 세션이 충돌하는 것 같아서요.)

daybreaker (2008-07-08 13:25:25)에 의해 마지막으로 수정

문제의 답은 우리 안에 있다.
내면에 귀를 기울여 보자.

5

답글: session_start 함수를 rewrite.php 에 넣고싶은데...

pass.php

<?
function movepage($url,$msg=""){
    echo "<script>";
    if($msg) echo "alert('$msg');";
    if($url=="history.go(-1)"){
        echo "history.go(-1);";
    }else{
        echo "location.replace('$url');";
    }
    echo "</script>";
    exit;
}
header ("P3P : CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\"");
session_start();

// 보안 필터링
if(!eregi(getenv("HTTP_HOST"),getenv("HTTP_REFERER"),getenv("HTTP_GET"))) movepage("history.go(-1)","정상적으로 접근하여주세요.");

// 정상적 절차로 왔을경우, 새션을 구워주세요...
if(!$_SESSION[cookie]) {
    $_SESSION[cookie]=7;
    $session_id = substr($_SESSION[session_id],1); // 0.5 으로 끊어서 0.5 + 0.5 = 1값으로...
}
movepage("./../tc/index.php");
?>

/tc/lib/session.php 에 다음과 같이 넣었는데 가능할까요?

function setSession() {
    if( !empty($_GET['TSSESSION']) ) {
        $id = $_GET['TSSESSION'];
        $_COOKIE[session_name()] = $id;
    } else if ( !empty($_COOKIE[session_name()]) ) {
        $id = $_COOKIE[session_name()];
        $cookie = $_SESSION[cookie];    //pass.php
    } else {
        $id = '';
    }
    if ((strlen($id) < 32) || !isSessionAuthorized($id)) {
        setSessionAnonymous($id);
        setSessionAnonymous($cookie);    //pass.php
    }
}