1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
<?php
//pour que la réponse s'affiche comme du texte brut
header('Content-Type: text/plain');
/*partie à modifier*/
$name = 'wwww.mon-site.fr';//nom du site
//pour ne pas devoir calculer à la main la longueur du corps, on le stocke dans une variable et la fonction strlen() nous la donne.
$data = "page=".$_SERVER['REQUEST_URI']."&ip=".$_SERVER['REMOTE_ADDR'];
//la requête
$envoi = "POST / HTTP/1.1\r\n";
$envoi .= "Host: ".$name."/mon_script_a_executer.php\r\n"; // j'ai un doute à ce niveau
$envoi .= "Connection: Close\r\n";
$envoi .= "Content-type: application/x-www-form-urlencoded\r\n";
$envoi .= "Content-Length: ".strlen($data)."\r\n\r\n";
$envoi .= $data."\r\n";
/*/partie à modifier*/
/*ouverture socket*/
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket < 0){
die('FATAL ERROR: socket_create() : " '.socket_strerror($socket).' "');
}
if (socket_connect($socket,gethostbyname($name),80) < 0){
die('FATAL ERROR: socket_connect()');
}
/*/ouverture socket*/
/*envoi demande*/
if(($int = socket_write($socket, $envoi, strlen($envoi))) === false){
die('FATAL ERROR: socket_write() failed, '.$int.' characters written');
}
/*/envoi demande*/
/*lecture réponse*/ //indispensable ou pas ?
$reception = '';
while($buff = socket_read($socket, 2000)){
$reception.=$buff;
}
echo $reception;
/*/lecture réponse*/
socket_close($socket);
?> |