dongtaijiao7140 2012-06-11 09:14
浏览 95
已采纳

即使在放入ob_start()之后,头函数也不起作用; [重复]

Possible Duplicate:
Headers already sent by PHP

I have the following code in my php file. I want to redirect from this page using header function which is clear in code below. I have made sure that there are no echo commands and have also placed ob_start(); at the beginning of the file yet i am getting the following error:

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web054/b548/ipg.psdingcampsduscom/facebook_registration_plugin/store_user_data.php:1) in /hermes/bosweb/web054/b548/ipg.psdingcampsduscom/facebook_registration_plugin/store_user_data.php on line 171

here is the code :

<?php ob_start();
            define('FACEBOOK_APP_ID', 'xxxxxxxx');
            define('FACEBOOK_SECRET', 'xxxxxxxxxx');
            // No need to change function body
            function parse_signed_request($signed_request, $secret) {
                list($encoded_sig, $payload) = explode('.', $signed_request, 2);
                // decode the data
                $sig = base64_url_decode($encoded_sig);
                $data = json_decode(base64_url_decode($payload), true);
                if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
                    error_log('Unknown algorithm. Expected HMAC-SHA256');
                    return null;
                }
                // check sig
                $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
                if ($sig !== $expected_sig) {
                    error_log('Bad Signed JSON signature!');
                    return null;
                }
                return $data;
            }
            function base64_url_decode($input) {
                return base64_decode(strtr($input, '-_', '+/'));
            }
            if ($_REQUEST) {
                $response = parse_signed_request($_REQUEST['signed_request'],
                                FACEBOOK_SECRET);
header("location: fbwe/step2.php?name=".$name."&email=".$email."&gender=".$gender."&arts=".$cb1."&act=".$cb2."&cooking=".$cb3."&dance=".$cb4."&designing=".$cb5."&fashion=".$cb6."&interior=".$cb7."&modeling=".$cb8."&photography=".$cb9."&poetry=".$cb10."&programming=".$cb11."&reading=".$cb12."&sketching=".$cb13."&singing=".$cb14."&sports=".$cb15."&stunting=".$cb16."&videography=".$cb17."&other=".$cb18);

                // Connecting to Database

            } else {
                //echo '$_REQUEST is empty';
            }
            ?>

Can anyone figure out what is wrong?

  • 写回答

1条回答 默认 最新

  • douchenchepan6465 2012-06-11 09:25
    关注

    Few things that should be keep in mind before using header function.

    1. There should be no echo or print statement before the header function.
    2. There should be no space on top and bottom of the page i.e page should start with <?php and end with ?>. There must be no blank space after or before these tags.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图