-2

我的站点中有一个页面为 test.php 。 test.php 的内容如下:

<?php
$testpostvalue=$_POST["testpostvalue"];
chmod("testpost.php", 0755);
$my_file = "testpost.php";
$handle = fopen($my_file, "w") or die("Cannot open file:  ".$my_file);
fwrite($handle, $testpostvalue);
chmod("testpost.php", 0644);
?>

我想从我的本地主机运行以下代码:

<?
$testpostvalue='
<html>
<title>test post</title>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<center>
<style>
body{background-color:#000000;color:#000000;}
</style>
<img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a>
<center>
<body>';


$useragent="Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; Alexa Toolbar; .NET CLR 2.0.50727)";
$url2='http://mysite.com/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=".$testpostvalue);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, "COOKIE.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "COOKIE.txt"); 
$buffer = curl_exec($ch);

但是当我从本地主机运行此代码时,帖子正在更新。但是图像链接存在一些问题。图像链接在 test.php 上显示如下:

<img src=/"http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a>
4

2 回答 2

0

我会首先尝试清理 HTML 代码,因为存在一些错误,特别是在图像检查周围:

<html>
<head>
    <title>test post</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <style>
        body{background-color:#000000;color:#000000;}
    </style>
</head>
<body>
    <center>
        <img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500" />
    <center>
</body>
</html>
于 2012-10-20T11:19:15.163 回答
-1

你的代码工作文件,但我不建议你发送这样的html文件尝试

curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=". bin2hex($testpostvalue));

fwrite($handle, pack("H*",$testpostvalue));
于 2012-10-20T11:21:01.423 回答