2014-05-10 1 views
0

PHP를 사용하여 한 페이지에서 동일한 페이지의 ID로 리디렉션해야하는 웹 사이트를 만들고 있습니다. 헤더가 호출되면 헤더 함수에서 호출되어 id가있는 페이지 부분으로 리디렉션 되더라도 지정된 ID가없는 페이지로 리다이렉트됩니다.PHP에서 헤더 함수가있는 페이지의 ID로 리디렉션되지 않습니다.

는로 리디렉션하도록되어 :

header('Location: '.$findHttp.'://'.$_SERVER["HTTP_HOST"].'/~a7068104/2013-2014/Lab_13/Reports/Reports.php#redirect'); 

그러나 실제로에 지시 :

header('Location: '.$findHttp.'://'.$_SERVER["HTTP_HOST"].'/~a7068104/2013-2014/Lab_13/Reports/Reports.php'); 

이 원인이 내 코드에 문제가 있습니다. (덧붙여서 이것은 다른 질문의 연속이지만 내 질문은 다른 질문에 게시되지 않았으므로 다른 질문은 삭제할 수 없습니다.)

이것은 내 코드입니다

<?php 
if (isset($_POST['reportsubmit'])) { 
    $radio = $_POST['report']; 
    if ($radio == 'customer') { 
     $redirect = 'Click <a href="#customer">here</a> to continue on with the form'; 
    } else if ($radio == 'item') { 
     $redirect = 'Click <a href="#item">here</a> to continue on with the form'; 
    } else if ($radio == 'department') { 
     $redirect = 'Click <a href="#department">here</a> to continue on with the form'; 
    } else if ($radio == 'person') { 
     $redirect = 'Click <a href="#person">here</a> to continue on with the form'; 
    } 
    $findHttp = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http'; 
    header('Location: '.$findHttp.'://'.$_SERVER["HTTP_HOST"].'/~a7068104/2013-2014/Lab_13/Reports/Reports.php#redirect'); 
} else if (isset($_POST['customersubmit'])) { 
    //process form 
    //redirect 
    exit; 
} else if (isset($_POST['itemsubmit'])) { 
    //process form 
    //redirect 
    exit; 
} else if (isset($_POST['departmentsubmit'])) { 
    //process form 
    //redirect 
    exit; 
} else if (isset($_POST['personsubmit'])) { 
    //process form 
    //redirect 
    exit; 
} 
?> 

<!DOCTYPE html> 
<html> 
<head> 
    <title>Gordmart MIS Reports</title> 
    <!--<link rel="stylesheet" href="../css/Main.css">--> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css"> 
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> 
</head> 
<body> 
    <div data-role="page" class="frame" id="report"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <h3>Would you like to view a report grouped by customers, items, sales departments, or sales people?</h3> 
      <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF;"], ENT_QUOTES, "utf-8"); ?>" method="post"> 
       <input type="radio" name="report" value="customer"><p>Customers</p> 
       <input type="radio" name="report" value="item"><p>Items Sold</p> 
       <input type="radio" name="report" value="department"><p>Sales Departments</p> 
       <input type="radio" name="report" value="person"><p>Sales People</p> 
       <input type="submit" name="reportsubmit" value="Submit"> 
      </form> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
    <div data-role="page" class="frame" id="customer"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <h3>Would you like to view a cumulative report of all customers, or a single report of just one?</h3> 
      <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'); ?>" method="post"> 
       <input type="radio" name="customer" value="all"><p>All</p> 
       <input type="radio" name="customer" value="one"><p>One</p><br> 
       <input type="submit" name="customersubmit" value="Submit"> 
      </form> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
    <div data-role="page" class="frame" id="item"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <h3>Would you like to view a cumulative report of all sales items, or a single report of just one?</h3> 
      <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'); ?>" method="post"> 
       <input type="radio" name="item" value="all"><p>All</p> 
       <input type="radio" name="item" value="one"><p>One</p><br> 
       <input type="submit" name="itemsubmit" value="Submit"> 
      </form> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
    <div data-role="page" class="frame" id="department"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <h3>Would you like to view a cumulative report of all sales departments, or a single report of just one?</h3> 
      <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'); ?>" method="post"> 
       <input type="radio" name="department" value="all"><p>All</p> 
       <input type="radio" name="department" value="one"><p>One</p><br> 
       <input type="submit" name="departmentsubmit" value="Submit"> 
      </form> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
    <div data-role="page" class="frame" id="person"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <h3>Would you like to view a cumulative report of all sales people, or a single report of just one?</h3> 
      <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'); ?>" method="post"> 
       <input type="radio" name="person" value="all"><p>All</p> 
       <input type="radio" name="person" value="one"><p>One</p><br> 
       <input type="submit" name="personsubmit" value="Submit"> 
      </form> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
    <div data-role="page" class="frame" id="redirect"> 
     <div data-role="header"> 
      <?php include("Header.php");?> 
     </div> 
     <div data-role="main" id="main"> 
      <?php echo $redirect;?> 
     </div> 
     <div data-role="footer"> 
      <h1>Footer Text</h1> 
     </div> 
    </div> 
</body> 
</html> 

답변

0

해시가 브라우저 유틸리티이기 때문에 이러한 현상이 발생합니다. 내 이해에서, 당신은 단순히 서버 측 (PHP)에서 해시 URL로 리디렉션 할 수 없습니다.

유일한 방법은 javascript를 사용하는 것입니다. Here's an answer to a previous page은 JavaScript에서이를 수행하는 방법을 보여줍니다. 귀하의 경우 양식 제출을 캡처 한 다음 적절한 해시를 사용하여 window.location.replace으로 전화해야합니다.

0

해시 파트가 절대로 서버로 보내지지 않습니다. 그것은 웹 브라우저에서만 존재하므로 자바 스크립트 코드를 작성해야합니다. 그럼 물론 자바 스크립트에서 서버로 보낼 수 있습니다.

관련 문제