Hi all,
I'm making a script to post data (using POST, can't do it via get) to another server (which I don't have access to) and that dir is protected via .htaccess (basic). I do have login of course
This is my code:
function put_code($imei, $email){
$data = "text1=$imei&text2=$email&dropdown=Other&new=";
$username = "test";
$password = "test";
$authentification = base64_encode($username.':'.$password);
$authline = "Authorization: Basic $authentification\r\n";
//if (!empty($referer)) {
$refererline = "Referer: http://www.somepage.com/index.php\r\n";
//}
$url = "http://www.somepage.com/index.php";
$url_info=parse_url($url);
$port = isset($url_info['port']) ? $url_info['port'] : 80;
$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 30);
if($fp) {
$head = "POST ".@$url_info['path']."?".@$url_info['query']." HTTP/1.1\r\n";
if (!empty($url_info['port'])) {
$head .= "Host: ".@$url_info['host'].":".$url_info['port']."\r\n";
} else {
$head .= "Host: ".@$url_info['host']."\r\n";
}
$head .= "Content-type: application/x-www-form- urlencoded\r\n";
$head .= "Content-length: " . strlen($data) . "\r\n";
$head .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13\r\n";
$head .= "Connection: keep-alive\r\n";
$head .= "Keep-Alive: 300\r\n";
//$head .= $data;
$head .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$head .= "Accept-Language: en-gb,en;q=0.5\r\n";
$head .= "Accept-Encoding: gzip,deflate\r\n";
$head .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$head .= $refererline;
$head .= $authline;
$head .= "\r\n";
$head .= $data . "\r\n";
//echo "Head:<br />$head <br /><br />";
if(fputs($fp, $head) != FALSE){
//fputs($fp, $data);
echo "<br />test";
while(!feof($fp)) {
if(!$content .= fgets($fp,2048)) {
return FALSE;
}
}
fclose($fp);
echo "<br />done<br /><br />";
echo $content;
//check if it was succesfull:
if(strstr($content, '<font face=tahoma size=2 color=red><b>successfully saved </b></font>')){
echo "<br />test";
return TRUE;
}
echo "<br /><br />headers:<br />" . $head;
}
}
}
if(put_code("22222222", "test3%40test3.nl") == TRUE){
echo "<br />all done";
}
else{
echo "<br />error";
}
The header sent is:
POST /user/index.php? HTTP/1.1
Host: www.netlock.mobi
Content-type: application/x-www-form- urlencoded
Content-length: 57
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Connection: keep-alive
Keep-Alive: 300
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Referer: http://www.netlock.mobi/user/index.php
Authorization: Basic Z3Vlc3Q6Z3Vlc3Q=
text1=22222222&text2=test3%40test3.nl&dropdown=Other&new=
There is lot of useless data in the header now (anyway I think) but now i'm just exactly copying the stuff my browser does.
Basically I'm filling out a form on that website only then automatically, I've been trying a couple days now but the data does not get into the system on the other server...
The logging in does work because I'm able to read out the HTML and echo that all back on my own website, but it just does not recognice POST data or accept it..
Who has any idea?
Thank you very much
With best regards,
Steven