Last active
April 10, 2018 15:32
-
-
Save ricardosaraiva/e3b92da5e6b5b3f46584fb41f66f5ab8 to your computer and use it in GitHub Desktop.
Curl para pegar conteúdo em sistemas que precisa de login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$usuario = 'usuario'; | |
$senha = 'senha'; | |
$urlLogin = 'http://www.radiooncologia.com.br/login'; | |
$urlPainel = 'http://www.radiooncologia.com.br/painel'; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $urlLogin); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_TIMEOUT, 5); | |
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, sprintf('email=%s&senha=%s',$usuario, $senha)); | |
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . DIRECTORY_SEPARATOR . 'cookie'); | |
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . DIRECTORY_SEPARATOR . 'cookie'); | |
$dados = curl_exec($curl); | |
curl_close($curl); | |
$cookie = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'cookie'); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $urlPainel); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_TIMEOUT, 5); | |
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
curl_setopt($curl, CURLOPT_COOKIE, $cookie); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$dados = curl_exec($curl); | |
echo $dados; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment