我有一個網頁在我的網站test.php的。而test.php的內容如下: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);
但是當我運行從我的本地後正在該代碼updated.But有一些問題與圖像link.The圖像鏈接出現這樣的test.php的:
<img src=/"http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a>
可能工作,但不捲曲應該是安全的?你爲什麼會這樣建議?多一點學習是一個誠實的問題。 – PatomaS
測試它,看到的是,由於您使用的是'CURLOPT_POSTFIELDS'。與二進制字符..輸出可能無法按預期 – Baba
@ BABA 我用你的第一個advise.but輸出來 ????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ??????????????????????????????? d ????????? –