helloxielan 2015-03-15 06:51 采纳率: 0%
浏览 34

如果$ s无效,则重定向

This is code from ajax script, after computing through all the necessary conditions $n and $view are created and displayed with the following code

<?php
//ajax conditions
?>
<data>
<handler value="show_view"/>
<item id="view<?php echo $n;?>" 
value="<?php echo rawurlencode($view);
        if (strpos($s,'invalid') !== false) 
        {
         echo "Hit Invalid";
         $url = $_SERVER['HTTP_REFERER'];
         header( "Location: $url" ); //<--not working   
         exit;
        }
      ?>"/>
<item id="end" value=""/>
</data>

I have $s in script..all i want to do is redirect script if the variable $s in invalid..script works fine but redirect doesn't work. Please suggest some solution to this problem. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • weixin_33671935 2015-03-15 07:31
    关注

    Why not put the header where you have the conditions at the very top? for the location header it needs to be outputted first before anything else.

    Since i am unsure what your trying to accomplish with adding stuff to value=" if you just want a quick redirect you could just hand it over to javascript to do.

    value="<?php echo rawurlencode($view);?>" />
    <?php
    if (strpos($s,'invalid') !== false) 
    {
    ?>
        <script>
          top.window.location = '<?php echo $_SERVER['HTTP_REFERER']; ?>';
         </script>
    <?php 
    } 
    ?>
    

    I would suggest re-visiting what your trying to do and tackle it another way as this is not ideal.

    评论

报告相同问题?