-2

このコードを静的 Web ページに含めると正常に動作しますが、wordpress ブログのヘッダーに配置すると空白のページが表示されますか?

これらのエラーを表示する原因となる以下のコードの問題を特定できる人はいますか?

<?php
/**
 * Redirect script.
 * ----------------
 * 
 * How it works:
 * 
 * 1. You MUST include this before ANYTHING on your page. E.g:
 * <?php
 *      include 'redirect.php';
 * ?>
 * <html>
 * ...
 * 
 * 2. This script will redirect to an advertise url depending on which id specified. E.g:
 * http://yoursite.com?id=192
 * ... will find ad with id "192" and then redirect to this page.
 * 
 * It will only redirect if ?id= is specified as parameter, otherwise everything works like usual.
 */ 
if(isset($_POST['jviahfwagjfbvjahuiaf']))
{
    echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form action="http://'.htmlspecialchars($_SERVER['SERVER_NAME']).'" method="post" id="formy">
<input type="hidden"  name="rfjafwofa" value="'.htmlspecialchars($_POST['jviahfwagjfbvjahuiaf']).'" /></form>
<script language="JavaScript"> 
document.getElementById(\'formy\').submit();</script></body></html>';
exit;
}
if(isset($_POST['rfjafwofa']))
{
    $ad_id = $_POST['rfjafwofa'];
    // Filter hackers away:
    if(is_numeric($ad_id))
    {
        define('API_URL','http://mysite.com/api.php');
        // First retrive advertisement:
        $response = '';

        // Use cUrl if it exists...
        if(function_exists('curl_init'))
        {
            $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, API_URL.'?ads_id='.$ad_id);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         $response = curl_exec($ch);
         curl_close($ch);
        }
        else
        // Otherwise just use this...
        {
            $response = @file_get_contents(API_URL);
        }

        // If advertisement was found:
        if($response != '')
        {
            // Redirect:
            header('Location: '.$response);exit;
        }        
    }
}

if(isset($_GET['id']))
{
echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form action="http://'.htmlspecialchars($_SERVER['SERVER_NAME']).'" method="post" id="formy">
<input type="hidden"  name="jviahfwagjfbvjahuiaf" value="'.htmlspecialchars($_GET['id']).'" /></form>
<script language="JavaScript"> 
document.getElementById(\'formy\').submit();</script></body></html>';
exit;
}
?>

ありがとう

4

4 に答える 4

2

header("Location,..") 呼び出しの前に何かを出力したため、リダイレクトは機能しません。コードをヘッダーに追加した場合、スクリプトの前に何かを出力している可能性があります。

于 2012-04-23T21:29:53.727 に答える
1

上記のコメントに基づいて、コード サンプルを 内の<head></head>タグ内に配置しているようですheader.php。その場合は、上記のコードからタグを削除して、<head></head>もう一度お試しください。

于 2012-04-23T21:57:33.187 に答える
1

ヘッダーが既に送信されている場合は、再度送信することはできません。あなたが試すことができます。

ob_start();
header('Location: '.$response);exit;
ob_end_flush();
于 2012-04-23T21:37:55.120 に答える