PHP - How to get cookies when logging into website? - php

I tried getting the cookie file from logging into the site binweevils, but i am unable to do so.
I have entered the correct values to be posted to the API, but for some reason it is telling me to enable cookies.
function login() {
$curl = curl_init("http://lb.binweevils.com/php2/login/logUserIn.php");
curl_setopt($curl, CURLOPT_POST, true);
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36');
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT);
curl_setopt($curl, CURLOPT_POSTFIELDS, "userID="."mo_salah"."&password="."test"."&rememberMe=1&submitted=1&x=".mt_rand(1, 200)."&y=".mt_rand(1, 100));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_COOKIEJAR, "sitecookies.txt");
$header = curl_exec($curl);
curl_close($curl);
print($header);
if(preg_match('/http:\/\/play\.binweevils.com\?res\=(.*?)\n/', $header))
return false;
return true;
}
If anyone can help me with this, it will be deeply appreciated.
The point : is to get cookies from this website.

Related

PHP data fetch script working in localhost but not working in hosting with ssl

i want to fetch data from user input url. i tried in localhost it is working but when uploaded to hosting it is not working.
Please help regarding this.
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
//browser's user agent string (UA)
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.47 Safari/537.36');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;}
//Checking for the json data in fetched content
$pattern = '/window._sharedData = (.*) /';
preg_match($pattern, $data, $matches);
//checking if we got the data or not
if(!$matches){
$response['status'] = 'fail';
echo json_encode($response);
exit; }
//getting json from content
$json = $matches[1];
//decoding json to process
$data = json_decode($json, true);
You need to check that Curl is installed or not to php on your server.
Run following line in your index php file.
curl_getinfo($ch)
If ıt'not installed, then import curl.

Get video source url from player on URL

I am trying to get video source URL from URLs like this one:
http://www.streamuj.tv/video/4a95f29bafc661c688a6?remote=1
I want to get this url:
http://s2.streamuj.tv:8080/vid/01c5cbf5cb2893dcba25518aa7fd84b2/58d669ce/4a95f29bafc661c688a6_sd.flv?start=0
A have tried to use CURL, but it hasn't helped yet.
Here is my code with CURL:
<?php
session_start();
include "simple_html_dom.php";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.streamuj.tv/video/4a95f29bafc661c688a6?streamuj=original&authorize=ac13bb77d3d863ca362315b9b4dcdf3e');
curl_setopt($curl, CURLOPT_FILETIME, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_PROXY, "189.3.93.114:8080");
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2950.0 Iron Safari/537.36' ));
$header = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
echo $info['url'];
// print "http://www.streamuj.tv/video/4a95f29bafc661c688a6?streamuj=original&authorize=ac13bb77d3d863ca362315b9b4dcdf3e"
?>
Any solutions using PHP or Python? Thanks!

Not able to access to site contents with PHP/CURL

$ch2 = SSLCURL("https://www.tcpvpn.com/create-tcpvpn-account-server");
curl_setopt($ch2, CURLOPT_REFERER, "https://www.tcpvpn.com/free-vpn-server-continent-europe");
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, "server=115");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$ex = curl_exec($ch2);
echo nl2br(str_replace("<","!!",$ex));
curl_close($ch2);
This is the code that I access to website. I handle cookies, SSL access, redirecting actions and UserAgent (Latest Chrome) on SSLCURL function.
The thing is when I access to that website over my browser or even with Glype (a proxy script written in PHP), I can reach to website without problem, but everytime I try to access over my script, I just get a meta redirection. How can I fix it?
edit: here comes the SSLCURL
function SSLCURL($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/jamjar.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/jamjar.txt");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept-Language:tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4",
"Connection:keep-alive",
"Upgrade-Insecure-Requests:1"
));
return $ch;
}

How to do a GET request on PHP using CURL

I have a simple GET request that I am trying to make and get the results back. I have tried it in Postman without any headers or body and it works just fine. I have even put it in my browser and it returns a good result. But, when I do it in PHP I am not getting anything. This is what my code looks like. What am I doing wrong?
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'http://********/vizportal/api/web/v1/auth/kerberosLogin');
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, '20');
$resp = curl_exec($curl);
echo $resp;
use this header to send header like browser to server :
$curl = curl_init('http://********/vizportal/api/web/v1/auth/kerberosLogin');
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, '20');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_HEADER, true);
// curl_setopt($curl, CURLINFO_HEADER_OUT, true); // enable tracking
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding:gzip, deflate, sdch',
'Accept-Language:en-US,en;q=0.6',
'Cache-Control:max-age=0',
'Connection:keep-alive',
'Host:www.********.tld ', // for example : www.google.com
'Referer: http://********/vizportal/api/web/v1/auth/kerberosLogin',
'Upgrade-Insecure-Requests:1',
'User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36',
));
$response = curl_exec($curl);
curl_close($curl);

php curl to read data from webpage

I am given a project on fetching data from this url.
For this, Simple HTML DOM process has already failed, so I am working on:
function curl_download($Url){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "www.idealo.de/preisvergleich/MainSearchProductCategory.html?q=0018208925063");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
print curl_download('www.idealo.de/preisvergleich/MainSearchProductCategory.html?q=0018208925063');
This code returns a blank page. Can anyone please help me?
The reason is the Useragent you used is too short to look like a real browser.
Try to use this one bellow:
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.38");

Categories