Skip to content

Instantly share code, notes, and snippets.

@numeroSette
Created June 20, 2012 05:14
Show Gist options
  • Save numeroSette/2958246 to your computer and use it in GitHub Desktop.
Save numeroSette/2958246 to your computer and use it in GitHub Desktop.
POST via fsockopen without recompile PHP, like a redirect with POST
<?php
$fp = fsockopen("localhost", 80, $errno, $errstr, 30);
$vars = array(
'hello' => 'world'
);
$content = http_build_query($vars);
fwrite($fp, "POST http://localhost/teste/test.php HTTP/1.1\r\n");
fwrite($fp, "Host: localhost \r\n");
fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-Length: ".strlen($content)."\r\n");
fwrite($fp, "Connection: close\r\n");
fwrite($fp, "\r\n");
fwrite($fp, $content);
header('Content-type: text/plain');
while (!feof($fp)) {
echo fgets($fp, 1024);
}
?>
<?php
echo "<br><br>";
$raw_data = $_POST;
//test 1
var_dump($raw_data);
echo "<br><br>";
//test 2
print_r( $_POST );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment