`
renzhelife
  • 浏览: 668860 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

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. header("Location:verify_reg.php" );
  3. exit;
  4. ....

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

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

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

  1. <?php
  2. /*
  3. *Testheader()inAndroid
  4. *
  5. */
  6. header("Location:http://www.baidu.com" );
  7. exit ;
  8. ?>

木有问题,那么只能有一种原因了,就是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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics