2011-07-26 34 views
1

好吧,我有以下一組頁面。他們獲取用戶信息,並將它們放入php會話變量中,以便最終啓用ajax的頁面可以使用它們。問題是隻有一些會話變量可用於服務器。某些會話變量在ajax請求中消失

這裏是流

input.php => input2.php, 
input2.php => control.php, 
control.php calls ajax requests to updateAjax.php 

input2.php://注意到文件名並投入會話

<?php 
     session_start(); 
     header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
    ?> 
    <?php 
     $_SESSION = array(); 
     $_SESSION['file'] = $_FILES['file']['name']; 
     mkdir("/blend/". $_FILES['file']['name']); 
     mkdir("/blend/" . $_FILES['file']['name'] . "/frames"); 
     move_uploaded_file($_FILES["file"]["tmp_name"], "/blend/". $_SESSION['file'] . "/scene.blend"); 
    ?> 

control.php //注意到從fourms並將其輸入到會話的用戶輸入vars

<?php 
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
    session_start(); 
    ?> 
    <?php 
     $_SESSION['endFrame'] = $_POST['frameEnd'] - 0; 
     $_SESSION['format'] = $_POST['format']; 
     $_SESSION['currFrame'] = $_POST['frameStart'] - 1; 
    ?> 

當我使用var_dump來檢查會話中的變量時,它的所有好處直到updateAjax.php爲c alled

updateAjax.php

 <?php 
     header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
     session_start(); 
     ?> 
     <?php 
      /*for blender internal render engine*/ 
      init(); 

      function init() { 
       sendInfo(); 
      } 

      function sendInfo() { 
       $output = array(); 
       $output['status'] = $_SESSION['file']; 
       $output['currFrame'] = $_SESSION['currFrame']; //Var is -1! 
       $output['lastFrame'] = $_SESSION['endFrame']; //var is 0! 
       echo json_encode($output); 
      } 
    ?> 

輸出[ 'lastframe']和currframe等於0和-1分別,無論你acually放在前幾頁中。會話[文件]不過是正確的......

要總括起來:

  1. 轉到input.php並上傳您的文件
  2. 會議[「文件」]可用;
  3. 去input2.php
  4. 會議[ 'currframe'],endframe,和格式正確無誤
  5. 去control.php
  6. 所有的會話瓦爾可用
  7. updateAjax.php只能訪問會話['file'],沒有任何其他

任何想法可能是我的問題? 感謝您幫助我了:),並詢問你是否需要更多的信息,虐待很樂意幫助

回答

0

control.phpupdateAjax.php,你不能調用session_start()前發送標題。反轉這些的順序:

<?php 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
session_start(); 
?> 

// Should be 
<?php 
session_start(); 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
?> 

PHP應該對此發出警告。檢查您的Web服務器錯誤日誌。

+0

感謝您的意見:) –

+0

雖然它仍然沒有解決我的主要問題:( –