我的站点中有一个页面为 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>