2011-08-04 10 views
0

すべてのスタイルシート、jsなどのファイルが含まれているindex.phpファイルがあり、index.phpのコンテンツ領域のファイルはrequire onceを使用して変更されます。他のいくつかのページセッションが失われています....そしてセッション変数は未定義です...これは私のindex.phpです...私はmain.phpにアクセスしている間にセッション変数が定義されていないエラーを受け取っています... ---- index .phpファイル-----URLのルーティング中に失われたセッションの価値

<?php session_start();?> 
<?php require_once("cc_includes/sessions.php"); ?> 
<?php require_once('cc_includes/functions.php'); ?> 
<?php require_once("cc_includes/sanitize.php"); ?> 
<?php require_once('cc_includes/route.php'); ?> 
<?php require_once("cc_includes/mydb.php"); ?> 
<?php 
    if($request_uri_header!='') 
    { 
     require_once($request_uri_header); 
    } 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <?php require_once("cc_includes/default_files.php");?> 
</head> 
<title><?php echo $the_title;?></title> 
<body id="page1"> 
<!-- header --> 
    <div class="bg"> 
     <section> 
      <?php require_once("cc_includes/message.php"); ?> 
      <div class="main"> 
       <header> 
        <?php require_once("cc_includes/logo.php"); ?> 
        <?php require_once("cc_includes/navigation.php");?> 
        <?php require_once("cc_includes/slider.php"); ?> 
       </header> 
       <section id="content"> 
        <div class="padding"> 
         <?php require_once("cc_includes/boxes.php"); ?> 
         <div class="wrapper"> 
          <div class="col-3"> 
           <div class="indent"> 
            <?php 
             if($request_uri!='') 
             { 
              require_once($request_uri); 
             } 
            ?> 
           </div> 
          </div> 
         </div> 
        </div> 
       </section> 
       <?php require_once("cc_includes/footer.php"); 
       require_once("cc_includes/end_scripts.php"); 
       ?> 
      </div> 
     </section> 
    </div> 
</body> 
</html> 

----- sessions.phpファイル------

$session_user=false; 
    $session_message=false; 
    if(!isset($_SESSION) || !isset($_SESSION['user'])) 
    { 
     $session_user=array(
       's_name'=>'', 
       's_gender'=>'', 
       'college_id'=>'', 
       's_joining'=>'Dynamic', 
       's_department'=>'Dynamic', 
       's_location'=>'', 
       's_dob'=>'', 
       's_approved'=>0 
      ); 
     $_SESSION['user']=serialize($session_user); 

    } 
    else 
    { 
     //print_r(unserialize($_SESSION['user'])); 
     //exit; 
     $session_user=unserialize($_SESSION['user']); 
    } 

-----route.ph Pファイル--------

if(isset($_GET['url'])) 
    { 
     $total_request=explode('/',$_GET['url']); 
     if(count($total_request)>1) 
     { 
      $_GET['url']=$total_request[0]; 
      array_shift($total_request); 
      $_GET['action']=$total_request[0]; 
      array_shift($total_request); 
      foreach($total_request as $key=>$value) 
      { 
       $_GET['param'.$key]=$value; 
      } 
      unset($total_request); 
     } 
     if($session_user['s_approved']!=0) 
     { 
      if($_GET['url']=='' || $_GET['url']=='index.php') 
      { 
       header("location: main.php"); 
      } 
      if(!is_file($_GET['url'])) 
      { 
       set_error_message("No Such Location Exits!"); 
       header("location: main.php"); 
      } 
      $request_uri=$_GET['url']; 
      $request_uri_header="headers/".str_replace('.php','.h',$request_uri); 

     } 
     else 
     { 
      $request_uri="users/login.php"; 
      $request_uri_header=str_replace('.php','.h',$request_uri); 
      if($_GET['url']!='' && $_GET['url']!='index.php') 
      { 
       if($_GET['url']=='services.php' || $_GET['url']=='register.php') 
       { 
        $request_uri=$_GET['url']; 
        $request_uri_header="headers/".str_replace('.php','.h',$request_uri); 
       } 
       else 
       { 
        if(is_file($_GET['url'])) 
        { 
         set_error_message("You need to Login Before Accessing Other Site Area!"); 
        } 
        else 
        { 
         set_error_message("No Such Location Exits!"); 
        } 
        header("location: index.php"); 
       } 
      } 
     } 
     if(!is_file($request_uri_header)) 
     { 
      $request_uri_header=''; 
     } 
    } 
    else 
    { 
     $request_uri="users/login.php"; 
     $request_uri_header=str_replace('.php','.h',$request_uri); 
    } 

---- main.hファイル-----

if(!registered_user() && !admin_user()) 
    { 
     set_error_message("Please Login To View The Page!",2); 
     header("Location: index.php"); 
    } 
    set_title("College Connections | Home"); 
    view_boxes(false); 
    view_slider(FALSE); 

----- main.phpファイル---- -

<?php 
    // if(!isset($session_user)) 
    //{ 
     //echo $session_user['s_name']; 
     //exit; 
    //} 
    //print_r($session_user); 
    //exit; 
    echo"<h1 class=\"profile\">".$session_user['s_name']."</h1><h1 class=\"blue_profile\">'s Profile</h1><a href=\"dashboard.php\" style='float:right;margin-right:30px;margin-top:20px;'>College Dashboard</a><br /></br /><br />"; 
    echo"<hr>"; 
    echo"<div class=\"prof_image\">"; 
    $c_id=$session_user['college_id']; 
    $image=mysql_query("select path from img_upload where username=\"$c_id\" limit 1",$connection); 
    if(!$image) 
    { 
     die("database query failed".mysql_error()); 
    } 
    echo mysql_error($connection); 
?> 

答えて

0

あなたはindex.phpの以外の任意のファイルにsession_start()呼び出されていないので、他のページがロードされたときにセッションが

+0

を失われているが、インクルードが呼び出されると、ファイルがindex.phpの中に含まれています。 ....そう なぜ私はすべてのファイルにセッションの開始を書く必要があります....そして、サイトはかなりライブですが、私はlocalhost上で実行するときに私はこのエラーが発生します – Birju

+0

($ request_uri!= '') { require_once($ request_uri); }をindex.phpに入れてroute.phpで操作した場合 – Birju

+0

「ユーザーが他のページを要求したとき」と書いたとき、これはindex.phpファイルには含まれていないページを参照していたと思います。さらにroute.phpは 'header(" location:main.php ")'を呼び出すときにindex.phpにロードされたコンテンツをmain.phpにリダイレクトするように見えます。手動でセッションを設定してください。なぜなら、彼らが仕事をするのは、セッションがデータなしで書き直されているからです。申し訳ありませんが、私は今実行する必要がありますので、私はこれ以上助けることはできませんが、私はこれが助けて欲しいです:) – Ryan

関連する問題