Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Eseguire nel codice richiesta http

    come si fa a simulare la richiesta di un browser ad una pagina php remota rispetto allo script passando anche dei valori get?

    immagino servano i socket, qualcuno mi posta un codice semplice?

    sono abilitati dappertutto?

    ciao,
    jack.

  2. #2
    Ciao
    Ti posto questo codice che ho rimediato su php.net e provato personalmente..
    Sono 2 funzioni, GET e POST, diciamo che ciò che devi settare è la variabile $query e host
    codice:
    $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)";
    
    function post($host,$query,$others='') { Global $useragent;
       $path=explode('/',$host);
       $host=$path[0];
       unset($path[0]);
       $path='/'.(implode('/',$path));
       $post="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n{$others}User-Agent: $useragent\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query";
       $h=fsockopen($host,80);
       fwrite($h,$post);
       for($a=0,$r='';!$a;){
           $b=fread($h,8192);
           $r.=$b;
           $a=(($b=='')?1:0);
       }
       fclose($h);
       return $r;
    }
    function get($host,$query,$others='') { Global $useragent;
       $path=explode('/',$host);
       $host=$path[0];
       unset($path[0]);
       $path='/'.(implode('/',$path));
       $post="GET $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n{$others}User-Agent: $useragent\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query";
       $h=fsockopen($host,80);
       fwrite($h,$post);
       for($a=0,$r='';!$a;){
           $b=fread($h,8192);
           $r.=$b;
           $a=(($b=='')?1:0);
       }
       fclose($h);
       return $r;
    }
    
    //ESEMPIO
    $host = "www.sito.com";
    $query = "var=54&prova=si";
    $altro = "";
    
    echo $test = post($host,$query,$altro);
    Occhiali da Sole www.OtticaGold.it
    Marche: Diesel, Dior, Emporio Armani, Gucci, Oakley, Oxydo, Police, Ray-Ban, Roberto Cavalli, Valentino, Vogue - Per le altre... cerca su google.it

  3. #3
    perfetto, funziona

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.