<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Request;

class Conductores extends Controller {


	public function obtenerConductor() {
		$from = 10000058;
		$to = 10000100;
		for ($i = $from; $i < $to; $i++) {
			sleep(3);
			$ch = curl_init();
			$fields = array('DNI' => "$i", 'DTYPE' => '1');
			$postvars = '';
			foreach ($fields as $key => $value) {
				if ($key == 'DNI') {
					$val = "&";
				} else {
					$val = '';
				}
				$postvars .= $key . "=" . $value . $val;
			}
			$headers = [];
			$header[0] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			$header[] = "Accept-Encoding	: gzip, deflate";
			$header[] = "Cache-Control: max-age=0";
			$header[] = "Connection: keep-alive";
			$header[] = "Cookie: ASPSESSIONIDQSDTCCRT=BCLGGJGCJPCDHLHIIJLLHLKE";
			$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
			$header[] = "Accept-Language: es-AR,es;q=0.8,en-US;q=0.5,en;q=0.3";
			$header[] = "Referer: http://www.psicofisicos.com.ar/LeftFrame.htm";
			//print_r($postvars);die();
			$url = "http://www.psicofisicos.com.ar/3.1.asp?" . $postvars;
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_POST, 1);                //0 for a get request
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
			curl_setopt($ch, CURLOPT_TIMEOUT, 20);
			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0");
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
			$response = curl_exec($ch);
			file_put_contents("conductores/" . $i . ".html", $response);
			curl_close($ch);
		}
	}


}