2011-11-28 55 views
0

我有一個打印用戶ID列表報告的程序。該程序應該爲上載列表中的用戶逐一打印報告。問題是,當我運行打印過程並獲得打印與indexInList = 30的報告中,我得到了錯誤:PHP重定向問題

This webpage has a redirect loop
The webpage at http://127.0.0.1/content/8520?print=1&bulkprinting=1&filename=/private/var/tmp/phpHRXEw8.moved&indexInList=30&nopeergroup=1&nolabpage=0&hideScreeningOnly=1&showOnlyScreening=0&hideHoldMailing=1 has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

我試圖清理Cookie,但還是繼續得到同樣的錯誤。

我附加了一些代碼在這裏,希望有人能幫助我:

$sessionData['first_name'] = $foundUser->first_name; 
    $sessionData['last_name'] = $foundUser->last_name; 

    // Overwrite $_REQUEST variable with parameters before including 
    // the hpa report 
    $_REQUEST = array(
    'user_id'  => $foundUser->id, 
    'bulkprinting' => true 
); 
    if($nopeergroup) { $_REQUEST['nopeergroup'] = $nopeergroup; } 
    if($nolabpage) { $_REQUEST['nolabpage'] = $nolabpage; } 
    if($hideScreeningOnly) { $_REQUEST['hideScreeningOnly'] = $hideScreeningOnly; } 
    if($showOnlyScreening) { $_REQUEST['showOnlyScreening'] = $showOnlyScreening; } 
    if($hideHoldMailing) { $_REQUEST['hideHoldMailing'] = $hideHoldMailing; } 

    $includeValue = include __DIR__.'/../hpa/hpa.php'; 

    $url = sprintf(
    "/content/8520?print=1&bulkprinting=1&filename=%s&indexInList=%s" . 
    "&nopeergroup=%s&nolabpage=%s&hideScreeningOnly=%s" . 
    "&showOnlyScreening=%s&hideHoldMailing=%s", 
    $filename, $indexInList, (int)$nopeergroup, (int)$nolabpage, 
    (int)$hideScreeningOnly, (int)$showOnlyScreening, (int)$hideHoldMailing); 

    if($hradata[0] !== false) { 
    $sessionData['hra_id'] = $hradata[0]['id']; 
    } 
    if($screeningdata[0] !== false) { 
    $sessionData['screening_id'] = $screeningdata[0]['id']; 
    } 

    if($includeValue !== 1) { 
    // Redirect to URL 
    $sessionData['message']  = $messages_set[$includeValue]; 
    $_SESSION['printing_set'][] = $sessionData; 

    redirect($url); 
    } 

    $sessionData['markAsMailed'] = true; 
    $_SESSION['printing_set'][] = $sessionData; 
?> 
<script type="text/javascript"> 
    function waitPrint() { 
    window.print(); 
    var t = setTimeout("timed()", 1000); 
    } 
    function timed() { 
    window.location.replace("<?php echo $url ?>"); 
    } 

    if(window.attachEvent) { 
    window.attachEvent("onload", waitPrint); 
    } else if(window.addEventListener) { 
    window.addEventListener("load", waitPrint, false); 
    } 
</script> 

回答

0

聽起來像是你有很多需要打印的文件!

您可能能夠更改您的瀏覽器設置(我似乎記得您可以在Firefox中)以允許超過30個循環。

或者,你總是可以限制你的代碼到30圈,然後等待進一步的用戶交互,以進入下一個30

第三選項是始終創建一個Word文檔或PDF,每個頁面上的一個報告,然後保存文件並打印出來 - 稍微麻煩一點,但至少你可以一次打印所有文件。

0

爲了$includeValue設置爲任何東西,文件__DIR__.'/../hpa/hpa.php'必須有它內部的一個return語句,如PHP documentationinclude證明,例如5 include只會返回一個值調用時,如果所包含的文件返回一個值。

如果腳本仍然產生無限循環,則包含文件中的邏輯不正確,並且始終產生的值不是1

從本質上講,這裏是你的問題歸結爲代碼:

$includeValue = include __DIR__.'/../hpa/hpa.php'; 
if($includeValue !== 1) { 
    // Redirect 
} 
+0

感謝您的回覆。你知道如何解決這個問題嗎? –

0

瀏覽器都有檢查內置幫助你,當網站被錯誤配置成重定向循環,和30必須是極限您正在使用的瀏覽器。您已經建立了重定向循環,但瀏覽器不知道。而不是使用window.location.replace()方法,如何自動提交表單?這應該看起來不同於瀏覽器,並允許您的循環按設計進行。

<script type="text/javascript"> 
    function waitPrint() { 
    window.print(); 
    var t = setTimeout("timed()", 1000); 
    } 
    function timed() { 
    window.reloadForm.submit(); 
    } 
    if(window.attachEvent) { 
    window.attachEvent("onload", waitPrint); 
    } else if(window.addEventListener) { 
    window.addEventListener("load", waitPrint, false); 
    } 
</script> 

<form name="reloadForm" action="<?php echo $url ?>"> 
</form>