$url_in = 'http://vk.com/video_ext.php?oid=3145131&id=159485516&hash=d821df23b7dc0b54&hd=1';
function curl($url, $cookie = false, $post = false, $header = false, $follow_location = false)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_location);
if ($cookie) {
curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
}
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec ($ch);
curl_close($ch);
return $response;
}
$vk_video = curl($url_in);
preg_match('|host=(.*)&|Uis', $vk_video, $link1);
preg_match('|uid=(.*)&|Uis', $vk_video, $link2);
preg_match('|vtag=(.*)&|Uis', $vk_video, $link3);
$link= $link1['1'].'u'.$link2['1'].'/video/'.$link3['1'].'.360.mp4';
echo $link;
the problem is that vtag= is different for every ip client so how can i retrieve the vtag with client ip?
Related
This is my function:
function postCurl($url, $jsql) {
$data = array('sql' => $jsql);//jsql is a json string
$headers = array('Content-Type: application/x-www-form-urlencoded');
var_dump($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
$output = curl_exec($ch);
return $output;
}
It always returns false. I've tried to make the same request with REST client and it works.
Check in the server whether curl is enabled or not!!
and use the below code
$data = array('name' => $_REQUEST['name']);
$ch = curl_init('www.example.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
curl_close($ch);
$xml_output = htmlentities($response);
This code not saving access token after verifying that this access token is valid or not instead of that it returns i=1. Eight hours ago this script work fine but it suddenly stop working.
<?php
function get_json($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data);
}
function get_html($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$token2 = $_GET["user"];
session_start();
if(isset($token2)){
if(preg_match("'access_token=(.*?)&expires_in='", $token2, $matches)){
$token = $matches[1];
}else{
$token = $token2;}
$exe = json_decode(get_html("https://graph.facebook.com/app?access_token=".$token ))->id;
$extend = get_html("https://graph.facebook.com/me/permissions?access_token=" . $token);
if($extend == true){
$pos = strpos($extend, "publish_actions");
if ($pos == true) {
$_SESSION['token'] = $token;
$ch = curl_init('http://my site/saver.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "token=".$token);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec ($ch);
curl_close ($ch);
header('Location:index.php');
}
else {
header('Location:index.php?i=1');}
//access token is not valid
}else{
header('Location:index.php?i=4');}
}else{
header('Location:index.php?i=2');}
?>
I'm trying to keep the session along different requests with curl when login into twitter because at some point it logs out from Twitter
$sTarget = "https://twitter.com";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie". $usuario ."_tweet.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, $usuario ."_tweet.txt");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_REFERER, $sTarget);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$html = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($c);
}
preg_match('<input name="authenticity_token" type="hidden" value="([a-zA-Z0-9]*)">', $html, $match);
$authenticity_token = $match[1];
if ($authenticity_token == "");
{
preg_match('<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token">', $html, $matchprima);
$authenticity_token = $matchprima[1];
}
$username = $usuario;
$password = "*******";
$sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token";
$sTarget = "https://twitter.com/sessions";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
# display server response
$htmldos = curl_exec($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $htmldos, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
var_dump($cookies);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
But when doing a var_dump in cookies to see if the cookies values are the same, under ["_twitter_sess"] I get different strings in the 2 requests. Shouldn't I get the same string if the session is kept between requests? If so, how do I do that?
This code works for logging in Twitter, and keeping session as for doing other things such after it as sending tweets. I've been using it for 6 months without problem. You need simple_html_dom.php from PHP Simple HTML DOM Parser for it to work
<?php
include_once('simple_html_dom.php');
global $usuario;
$usuario = "universohumor2"; //your twitter account username
$ch = curl_init();
/************************************** COMIENZAN LAS LLAMADAS A FUNCIONES *************************************/
/***************************************************************************************************************/
$vector_retorno = logueo_twitter($ch);
/******************************************************************************************************************/
function logueo_twitter($ch)
{
//$ch = curl_init();
global $usuario;
$sTarget = "https://twitter.com";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie". $usuario ."_tweet.txt");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_REFERER, $sTarget);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$html = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($c);
}
preg_match('<input name="authenticity_token" type="hidden" value="([a-zA-Z0-9]*)">', $html, $match);
$authenticity_token = $match[1];
if ($authenticity_token == "");
{
preg_match('<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token">', $html, $matchprima);
$authenticity_token = $matchprima[1];
}
$username = $usuario;
$password = "password"; // your twitter account password
$sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token";
$sTarget = "https://twitter.com/sessions";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
# display server response
$htmldos = curl_exec($ch);
//echo $htmldos;
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
$vector["sPost"] = $sPost;
$vector["authenticity_token"] = $authenticity_token;
return $vector;
}
?>
i maked this function:
function makeRequest($url,$browser,$ip,$cookie = false,$referrer = null)
{
if($referrer==null)
{
$refferer = 'http://google.com';
}
$headers = array();
$headers[] = "HTTP_X_FORWARDED_FOR: ".$ip;
$headers[] = "X_FORWARDED_FOR: ".$ip;
$headers[] = "REMOTE_ADDR:". $ip;
$headers[] = "REFERRER: ".$referrer;
$headers[] = $browser;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
if($cookie!==false)
{
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
}
else
{
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
}
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
if($cookie==false)
{
$return = curl_exec($ch);
}
else
{
$return = 'hidden content';
curl_exec($ch);
}
curl_close($ch);
return $x;
}
But everytime returning the content, if i already set cookie to false.
I don't know how can i do that.
I tried with:
CURLOPT_RETURNTRANSFER,
CURLOPT_VERBOSE,
CURLOPT_HEADER
But nothing...
Thank's (sorry for my eng)
I am trying to send POST data using CURL to an url. This URL is called by an iframe, which is in my application.
<iframe frameborder="0" width="950" height="1000" src="/tools/costs"></iframe>
public function costs()
{
$url = "http://someurl.com/tools/costs";
if($_POST)
{
$fields_str = http_build_query($_POST);
$query = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D',$fields_str);
$realstring = str_replace("%5D", "", str_replace("%5B", "", $query));
// $realstring echo:
var_carrier=3&var_carrier=5&var_carrier=6&var_service=Demurrage+%2F+Storage&var_service=Detention&var_pod=Ancona&var_pod=Antalya&var_pod=Antwerpen
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$realstring);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
}
else
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$fields_str = "";
}
echo $response;
}
but the $realstring variable is empty when i send it by cURL POSTFIELDS
I have no idea wy!