PHP redirection issue
<p>I have a program that prints reports for a user id list. The program is supposed to print reports one by one for users on the list uploaded. The problem is that when I was running the printing process and getting to print the report with indexInList=30, I got error: </p>

<blockquote>
  <p>This webpage has a redirect loop<br>
  The webpage at <a href="http://127.0.0.1/content/8520?print=1&amp;bulkprinting=1&amp;filename=/private/var/tmp/phpHRXEw8.moved&amp;indexInList=30&amp;nopeergroup=1&amp;nolabpage=0&amp;hideScreeningOnly=1&amp;showOnlyScreening=0&amp;hideHoldMailing=1" rel="nofollow">http://127.0.0.1/content/8520?print=1&amp;bulkprinting=1&amp;filename=/private/var/tmp/phpHRXEw8.moved&amp;indexInList=30&amp;nopeergroup=1&amp;nolabpage=0&amp;hideScreeningOnly=1&amp;showOnlyScreening=0&amp;hideHoldMailing=1</a> 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.</p>
</blockquote>

<p>I tried to clean the cookie but still keep getting the same error.</p>

<p>I attached some code here and hope anyone can help me:</p>

<pre><code>  $sessionData['first_name'] = $foundUser-&gt;first_name;
  $sessionData['last_name']  = $foundUser-&gt;last_name;

  // Overwrite $_REQUEST variable with parameters before including
  // the hpa report
  $_REQUEST = array(
    'user_id'      =&gt; $foundUser-&gt;id,
    'bulkprinting' =&gt; 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&amp;bulkprinting=1&amp;filename=%s&amp;indexInList=%s" .
    "&amp;nopeergroup=%s&amp;nolabpage=%s&amp;hideScreeningOnly=%s" .
    "&amp;showOnlyScreening=%s&amp;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;
?&gt;
&lt;script type="text/javascript"&gt;
  function waitPrint() {
    window.print();
    var t = setTimeout("timed()", 1000);
  }
  function timed() {
    window.location.replace("&lt;?php echo $url ?&gt;");
  }

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