-1

可能重复:
PHP 已发送的标头

我的 php 文件中有以下代码。我想使用下面的代码中清楚的标头函数从这个页面重定向。我确保没有 echo 命令,并且还放置了 ob_start(); 在文件的开头,但我收到以下错误:

警告:无法修改标头信息 - 标头已由 /hermes/bosweb/web054/b548/ipg.psdingcampsduscom/facebook_registration_plugin/store_user_data.php:1 中的 /hermes/bosweb/web054/b548/ipg.psdingcampsduscom/ 发送facebook_registration_plugin/store_user_data.php 在第 171 行

这是代码:

<?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';
            }
            ?>

谁能弄清楚出了什么问题?

4

1 回答 1

0

在使用 header 函数之前应该记住的几件事。

  1. 在 header 函数之前不应该有 echo 或 print 语句。
  2. 页面顶部和底部不应有空格,即页面应以 . 开头<?php和结尾?>。这些标签前后不能有空格。
于 2012-06-11T09:25:43.230 回答