Is it possible to capture PHP code from a page using CURL? [closed]

0

How do I run the PHP code of a particular page within my application, and I am not a holder of this application.

    
asked by anonymous 02.12.2015 / 22:21

2 answers

2

It is not possible to execute a third-party PHP code because the PHP code is sent to the server, processed and then returns an output in HTML, what you can do is capture only this output, and use only the parameters such as GET or POST.

The CURL only captures the page as it was processed by the server (this if the third party server allows and if you have CURL installed on your apache), if you want to use only this, this is the code to capture: p>

function capturarUrl($url_metodo)
{

    try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url_metodo);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $saida = curl_exec($ch);
            curl_close($ch);
    } catch (Exception $e) {
            $saida = file_get_contents($url_metodo);
    }
    return $saida;
}

echo capturarUrl('http://www.google.com.br');
    
20.04.2016 / 15:05
0

Here, but I do not recommend this, because I only use cURL to get the HTML of a page and treat. For example, when I want the inflation data from the Central Bank website, I use cURL.

#cria uma variável com a inicialização da função
$curl = curl_init();

#passa as opções para a função cURL
curl_setopt($curl, CURLOPT_URL, "caminho/pro/seu/arquivo.php"); //URL do arquivo .PHP. A URL pode ser passada por variavel também $url = "caminho/pro/seu/arquivo.php"
curl_setopt($curl, CURLOPT_HEADER, FALSE); //nao incluir os cabeçalhos na saida/resultado
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //retorna o curl_exec() como uma string, em vez de imprimir diretamente

#executa a sessão cURL
$resultado = curl_exec($curl);
#fecha a sessão cURL
curl_close($curl);

#imprime o resultado
echo $resultado;

curl_init() can receive the URL directly as well: curl_init("caminho/do/arquivo.php") . In this case, you can remove% with%.

    
02.12.2015 / 22:44