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

//ajax conditions
<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   
<item id="end" value=""/>

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);?>" />
    if (strpos($s,'invalid') !== false) 
          top.window.location = '<?php echo $_SERVER['HTTP_REFERER']; ?>';

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




    • ¥15 存储过程或函数中的结果集类型变量如何使用。
    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信