fwrite无法使用其他一些非特殊字符

时间:2018-08-22 08:38:57

标签: php fwrite

我有一个脚本可以将帖子发送到url。完整的代码不适用于以下示例,它不会显示任何错误

<?php
$posturl = 'https://sub1.domain.com/mailforward.php';
$message_array = array();
$message_array['From'] = 'WordPress <wordpress@sub2.domain.com>';
$message_array['To'] = 'me@domain.com';
$message_array['Subject'] = '[My Blog] Password Reset';

$message_array['Body'] = 'Someone has requested a password reset for the following account:

https://sub2.domain.com/dir/

Username: admin

If this was a mistake, just ignore this email and nothing will happen.

To reset your password, visit the following address:

<https://sub2.domain.com/dir/wp-login.php>';

post_async($posturl,$message_array);

function post_async($url, $params)
{
// Build POST string
foreach ($params as $key => &$val) {
  if (is_array($val)) $val = implode(',', $val);
  $post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);

// Connect to server
$parts=parse_url($url);
$fp = fsockopen($parts['host'],isset($parts['port'])?$parts['port']:80,$errno, $errstr, 30);

// Build HTTP query             
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
$out.= $post_string;

// Send data and close the connection
fwrite($fp, $out);
fclose($fp);
}

?>

但是,如果在变量$message_array['Body']中,如果我在最后一行中删除了.php(也就是将wp-login.php替换为wp-login),该脚本将预期的。

对此我感到非常惊讶,因为.php不包含任何特殊字符。

1 个答案:

答案 0 :(得分:0)

它现在显示可能出现错误,因为您的服务器上的php错误报告已关闭。 至少它显示您在声明函数之前在函数上调用此行的错误。

post_async($posturl,$message_array);

您应该打开服务器上的错误,以便了解所面临的问题。另外,您必须在函数声明后调用该函数。就像下面给出的...

function post_async($url, $params)
{
// Build POST string
foreach ($params as $key => &$val) {
  if (is_array($val)) $val = implode(',', $val);
  $post_params[] = $key.'='.urlencode($val);
}

post_async($posturl,$message_array);