Page Redirection not working after hosting

时间:2015-06-26 09:54:09

标签: php redirect

i am trying to redirect a page according to the text value using switch and button click, its working fine in localhost but not working after hosting. please help to overcome this problem.. looking forward to it. thanks.

form coding

<form id="accounForm" class="form-horizontal" method="post" action="redirect.php" >

<INPUT type="hidden" VALUE ="<?php echo( htmlspecialchars( $row['jewellery_name'] ) ); ?>"  name="textboxdata" >
 <INPUT TYPE = "Submit" class="btn btn-blue" Name = "submit" VALUE = "Add Another">



</form>

redirect.php

  <?php
  session_start();

  ob_start();
$textboxdata = $_POST['textboxdata'];

if (isset($textboxdata)) { 
switch ($textboxdata)
{
case COL:
  header("Location: new_item_5piececollar.php");
  exit();
      case BAB:
  header("Location: new_item_babybangle.php");
 exit();
  case BRR:
  header("Location: new_item_babyring.php");
  exit();
      case BAL:
  header("Location: new_item_balla.php");
 exit();
case BRC:
  header("Location: new_item_bracelet.php");
  exit();
      case BUT:
  header("Location: new_item_button.php");
 exit();
  case CNA:
  header("Location: new_item_chain.php");
  exit();
      case CHK:
  header("Location: new_item_choker.php");
 exit();
case CHR:
  header("Location: new_item_chur.php");
  exit();
      case CHU:
  header("Location: new_item_churi.php");
 exit();
  case DUL:
  header("Location: new_item_dull.php");
  exit();
      case FBA:
  header("Location: new_item_fullballaakshi.php");
 exit();
case GRR:
  header("Location: new_item_gentsring.php");
  exit();
      case HNK:
  header("Location: new_item_helenecklace.php");
 exit();
  case SOB:
  header("Location: new_item_hsocketbouti.php");
  exit();
      case JHU:
  header("Location: new_item_jhumka.php");
 exit();
case KAN:
  header("Location: new_item_kaan.php");
  exit();
      case LRR:
  header("Location: new_item_ladiesring.php");
 exit();
  case LKT:
  header("Location: new_item_locket.php");
  exit();
      case NKL:
  header("Location: new_item_longnecklace.php");
 exit();
case MAK:
  header("Location: new_item_makhri.php");
  exit();
      case MGS:
  header("Location: new_item_mangalsutra.php");
 exit();
  case MAN:
  header("Location: new_item_mantasha.php");
  exit();
      case NOA:
  header("Location: new_item_noah.php");
 exit();
case NOT:
  header("Location: new_item_noth.php");
  exit();
      case PDT:
  header("Location: new_item_pendent.php");
 exit();
  case POL:
  header("Location: new_item_pola.php");
  exit();
      case SAC:
  header("Location: new_item_sankha.php");
 exit();
case TAN:
  header("Location: new_item_tana.php");
  exit();
      case TCK:
  header("Location: new_item_tickli.php");
 exit();
  case TOP:
  header("Location: new_item_tops.php");
  exit();
  case NCK:
  header("Location: new_item_entry.php");
  exit();

      case WRI:
  header("Location: new_item_wrislet.php");
 exit();
  default:
  echo "Enter a number please.";
}
}
ob_end_flush();

?>     

4 个答案:

答案 0 :(得分:2)

在打开标签之前删除空白区域

答案 1 :(得分:1)

有一些小问题:

  1. 您不需要输出缓冲
  2. 您的开关案例不在引号中,因此它们将被解释为 常数而不是字符串
  3. 在开幕<?php
  4. 之前,您似乎有一些空格
  5. 您的重定向不是相对于文档根目录,所以如果这是在 子目录,他们可能不会重定向到您希望的地方
  6. 这样的事情应该解决这些问题:

    <?php
    session_start();
    
    $textboxdata = !empty($_POST['textboxdata']) ? $_POST['textboxdata'] : '';
    switch ($textboxdata) {
    
        case 'COL':
            header("Location: /new_item_5piececollar.php");
            exit();
    
        case 'BAB':
            header("Location: /new_item_babybangle.php");
            exit();
    
        /* ... and so on ... */
    
        default:
            echo "Enter a number please.";
            break;
    }
    

答案 2 :(得分:1)

正如OP在我的评论中所要求的那样,这是一个改进代码以缩短代码的建议。我的PHP有点生疏,我没有什么可以在这里测试所以希望没有语法错误,无论如何这个想法就在那里:

<?php
    session_start();
    ob_start();
    $textboxdata = $_POST['textboxdata'];
    $URL_array = array('COL' => 'new_item_5piececollar.php', 'BAB' => 'new_item_babybangle.php', 'BRR' => 'new_item_babyring.php');
    if (isset($textboxdata) && array_key_exists($textboxdata, $URL_array))
    { 
        header("Location: ".$URL_array[$textboxdata]);
    }
    else
    {   
        echo "Enter a number please.";
    }
    ob_end_flush();
?>  

请注意,为了示例,我在这里定义了$URL_array,但在某种配置文件中会更好,通过将配置与逻辑分离来改进代码:如果需要添加新元素,你不应该修改代码。

答案 3 :(得分:0)

Sometimes your output buffers are on if you're on a development server, but in most of the cases it's turned off on live-systems. Check your .INI file for the following parts:

http://php.net/manual/en/outcontrol.configuration.php

Otherwise check out that there is no output before the headers are sent.