Jump to content
Guest

Functie curl in php

Recommended Posts

Posted

O functie foarte utila pentru a usura lucrul cu curl, se salveaza intr-un fisier de exemplu curl.php si se include in fisierul php de lucru.

Se creaza folderul "cookies" unde vor fi stocate cookies pentru fiecare utilizator unic in parte , astfel evitam amestecarea lor (initial am pus sa salveze cookie in forma ip.txt - gen 127.0.0.1.txt dar cum multi provideri de internet pe mobil foloseau acelasi ip .... se amestecau).


<?php
if (!isset($_SESSION)) {
session_start();
}
$config['useragent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
$config['cookie_file'] = "./cookies/".session_id();
$config['proxy'] = "";
$config['proxy_port'] = "";

function curl($url='',$var=''){
global $config;
$curl = curl_init();
if (isset($config['proxy'])) {
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY, $config['proxy']);
curl_setopt($curl, CURLOPT_PROXYPORT, $config['proxy_port']);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,20);
curl_setopt($curl, CURLOPT_USERAGENT, $config['useragent']);
curl_setopt($curl, CURLOPT_REFERER, "http://google.com/");
if($var) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $var);
}
curl_setopt($curl, CURLOPT_COOKIE,''.$config['cookie_file']);
curl_setopt($curl, CURLOPT_COOKIEFILE,''.$config['cookie_file']);
curl_setopt($curl, CURLOPT_COOKIEJAR,''.$config['cookie_file']);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 3);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
?>

Iar functia functioneaza cam asa:


<?php
set_time_limit(3600);
include("curl.php");
if(!file_exists($config['cookie_file'])){
$fp = @fopen($config['cookie_file'],'w');
@fclose($fp);
}
$url = "http://google.com/login.php";
$var = "var1=9928727&var2=913891731";
$result = curl($url,$var);
echo $result;
?>

Acest exemplu face POST la variabile, dar daca aveti nevoie de GET folositi : $result = curl($url);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...