当我在静态网页上包含此代码时,它运行正常,但是当放入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;
}
?>
感谢
答案 0 :(得分:2)
重定向不起作用,因为您在标题(“Location,..”)调用之前已经输出了一些内容。如果您已将代码添加到标题中,则可能在脚本之前输出了一些内容。
答案 1 :(得分:1)
如果您的标头已经发送,则无法再次发送。 你可以试试。
ob_start();
header('Location: '.$response);exit;
ob_end_flush();
答案 2 :(得分:1)
根据上述评论,听起来您将代码示例放在<head></head>
内的header.php
标记内。如果是这样,请从上面的代码中删除<head></head>
代码,然后重试。
答案 3 :(得分:0)
使用标题和位置的标准php代码在单词press install
中不起作用header("Refresh: 1; URL=".$redirect);
你必须使用单词按功能,否则这是另一个对我有用的解决方案
echo "<meta http-equiv=\"refresh\" content=\"10;url=$redirect\" />";
我希望这会有所帮助