现在的位置: 首页 > 综合 > 正文

解决Android服务器端页面header无法跳转问题

2018年04月15日 ⁄ 综合 ⁄ 共 1164字 ⁄ 字号 评论关闭

from: http://blog.csdn.net/spring21st/archive/2011/06/28/6572145.aspx

 

由于当当Android客户端采用的是客户端请求,服务端response,返回页面的方式。

在调试中,发现当用户点击注册页面,提交后,通过



  1. header( 
    'Location:'
     . 
    $to_url
     );  
  2.     exit
    ;  

无法跳转到验证页面。

但是通过tail access_log ,发现其实是访问verify_reg.php 的。究竟是什么原因呢?

当我直接在页面顶部输入



  1. <?php  
  2.   
  3. header("Location:verify_reg.php"
    );  
  4. exit;  
  5.   
  6. ....  

可以直接跳转。使用浏览器进行访问都没有问题,真是苦恼呀。

问题肯定是出在header上,但是为什么浏览器可以,但是android客户端访问网页就出问题呢?是android的webview控件对header有限制?

我做了一个测试页面: header_test.php

  1. <?php  
  2. /* 
     
  3.  * Test header() in Android
     
  4.  *
     
  5.  */
      
  6.   
  7. header("Location:http://www.baidu.com"
    );  
  8. exit
    ;  
  9.   
  10. ?>  

木有问题,那么只能有一种原因了,就是register.php 注册成功,在执行 header("Location:") 方法 跳转到verify_reg.php 的时候,

页面没有生成,无法改写header的Location,那就采取 输出缓存


来解决吧。



  1. ob_start();  
  2.     header( 'Location:'
     . 
    $to_url
     );  
  3.     exit
    ;  
  4. ob_end_flush();  

OK!  O(∩_∩)O~ 从昨天晚上整到今天上午,终于搞定了。

使用HTML5+CSS3 的方式开发android客户端,开发成本和维护成本降低了,但是同时带来的是调试的复杂度。

这个对于不同项目还是需要进行评估的。

reference

PHP经典header错误"Cannot modify header information"的解决方法

http://beyondwarrior.blog.163.com/blog/static/110101770200982595033402/

header(Location:)应该注意的几个问题 

http://blog.cnlaoke.com/2009/08/03/51/

PHP header location 继续执行 exit

http://hi.baidu.com/kbsy/blog/item/8d9197f8e04f871cd9f9fd89.html

抱歉!评论已关闭.