get URL Answer with curl or json - php

I need to get the answer of a page.
The url looks like this:
sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=71&ppy=32&cid=48713&tcv=1355771664807&_=_585_204
The Answer I get looks like this:
{"module":"system","error":[],"syslist":{"15":{"con1":"0","con2":"0","kgm":"257506","kgk":"317370","kgt":"10300255","ppx":"71","ppy":"32","ppz":"15","pname":"Ckaleme","playerid":"5428","flag":"1","noob":"85315748","sperrflag":"-1","nick":"S7alker","tag":"-R-","pid":"707","allianzid":"707","inaktiv":1,"platz0":"82","punkte0":"187044480","platz1":"196","punkte1":"21326785","platz2":"87","punkte2":"105724483","platz3":"69","punkte3":"59993212","oldlogin":null,"nickdays":"0","isnoob":false}},"tflist":[],"ppx":71,"ppy":32,"allianzid":3225,"allianzpid":3225,"debug":{"parsetime":[{"name":"Start","parsetime_complete":"0.000","parsetime_last":"0.000"},{"name":"Ende","parsetime_complete":"0.014","parsetime_last":"0.014"}],"parsetime_total":"0.014","querytime":0.0026}}
I've tried with CURL, file_get_contents and so on ... but the answer was just an
www:redirect
Code edited....no result
$data = "http://some.site.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355426935816&_=_552_140";
$ch = curl_init($data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
The Page --> http://sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355511915397&_=_482_292
I get a json as answer
So ... after some days of tryin' I have no ideas anymore.
No idea, how to login there, to jump to a specified page and read the json from there.
maybe someone has an great idea to help me out.
LogIn Page is here --> http://sp2.looki.de/
:'(
Edit 2
I stuck ....
I've the following code now ...
$data1 = "http://sp2.looki.de/index.php?page=newsysview&cid=48713&ppx=50&ppy=50&cid=48713&tcv=1355511915397&_=_482_292";
$ch = curl_init ($data1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec ($ch);
in my var_dump($data) it's just an {"www-redirect": "/"}
WHY?
oh .... hint:
the original address is: http://sp2.looki.de/index.php?page=gui&cid=666#nothing
the address in $data1 seems to be an ajax request.

Ensure you have Follow Location active in your curl request:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Otherwise you are forcing it to not follow the "Location:" headers
http://php.net/manual/es/function.curl-setopt.php
Additionally, maybe the website doesn't allow direct query of that URL, try to trick it using the "Referer" value of curl
curl_setopt($ch, CURLOPT_REFERER, 'http://some.site.de/');

Related

How to make a call to .aspx https from php script from my localhost with xamp?

I am trying to send SMS from my localhost with xamp installed.
Requested page is on https and an .aspx page.
I am getting error: "HTTP Error 400. The request is badly formed." or blank page only in some cases.
Detaisl is as follows :
$url = 'https://www.ismartsms.net/iBulkSMS/HttpWS/SMSDynamicAPI.aspx';
$postArgs = 'UserId='.$username.
'&Password='.$password.
'&MobileNo='.$destination.
'&Message='.$text.
'&PushDateTime='.$PushDateTime.
'&Lang='.$Lang;
function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$response = getSslPage($all);
echo "<pre>";
print_r($response); exit;
I tried every possible solution/combination found on internet but could not resolve that. The API developers do not have a example for php script.
I tried httpful php library and file_get_contents function but getting empty page. Also tried every combination with curl_setup.
I need to call this url without any post data and see the response from it.
Instead getting a blank page.
Please note that when I execute the url with all details in browser it works fine.
Can anybody help me in this regard.
Thank you,
Usman
First do urlencode over your data as follows:
$postArgs = 'UserId='. urlencode($username.
'&Password='.urlencode($password).
'&MobileNo='.urlencode($destination).
'&Message='.urlencode($text).
'&PushDateTime='.urlencode($PushDateTime).
'&Lang='.urlencode($Lang);
After that two possible solutions. One is using GET.
curl_setopt($ch, CURLOPT_URL, $url . "?" . $postArgs);
Second option is using POST method.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs);

Unable to use file_get_contents(), returns nothing

I'm trying to get some data from a website that is not mine, using this code.
<?
$text = file_get_contents("https://ninjacourses.com/explore/4/");
echo $text;
?>
However, nothing is being echo'd, and the string length is 0.
I've done this method before, and it has worked no problem, but with this website, it is not working at all.
Thanks!
I managed to get the contents using curl like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://ninjacourses.com/explore/4/");
$result = curl_exec($ch);
curl_close($ch);
cURL is a way you can hit a URL from your code to get a html response from it. cURL means client URL which allows you to connect with other URLs and use their responses in your code
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://ninjacourses.com/explore/4/");
$result = curl_exec($ch);
curl_close($ch);
i think this is useful for you curl-with-php and another

curl will not redirect

Please excuse the probable simplicity of the question but I am new to curl and therefore finding my feet. I have the following which is in a php page and when called meant to post dept=xxx to mysite
$ch = curl_init( );
curl_setopt($ch, CURLOPT_URL,"http://mysite/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "dept=".$departmentName);
curl_exec ($ch);
curl_close ($ch);
I have 2 queries:
1) When called the screen goes blank and the user is not redirected.
2) If redirection is correct, am I right in thinking that the following will correctly receive the data posted:
if (isset($_POST["dept"]))
{
$deptName=$_POST["dept"];
}
Include this cURL paramter to your existing set.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

Using curl to bring search results from external site

I have 2 sites, one main, one external. On the main site, I am using Lucene to search through it. The problem is, I am trying to also search through the external site.
The Form action for the external site:
<form action="https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT" method="post" name="search_tribute" >
I've tried to use curl, but it only brings up the search form without actually doing the search (the field is empty as well).
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, tname='hello');
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
Any tips?
I don't have access to the form action since it's on an external site. All i have is a form that links to it when I submit it.
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("teamName" => "hello", "searchType" => "team"));
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
Can you try this?
I'm pretty sure it's supposed to be teamName instead of tName
Most search engine use GET and not POST .. you can try
// asumption
$_POST['search'] = "hello";
// Return goole Search Result
echo curlGoogle($_POST['search']);
function curlGoogle($keyword) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?hl=en&q=' . urlencode($keyword) . '&btnG=Google+Search&meta=');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Or if you want post then
curl_setopt($ch, CURLOPT_POSTFIELDS, array("search"=>"hello"));
Your php code is not valid syntax, it does not compile.
So if this is really what you have, your problem is that your file generates a fatal error.
That being said, this question is hard to answer since we don't know the site you want to grab your search results from.
Try modifying your line like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, "search=hello");
or alternatively
curl_setopt($ch, CURLOPT_POSTFIELDS, array("search" => "hello");
Maby it will work, however it may be that more post data is required or that the element name is not correct.
You have to look at the form or try making a request and look at it with chromes developer tools or firebug.
Also there are a number of ways for external sites to prevent what you are doing, altough evertything can be worked around somehow.
Assuming that is not the case, I hope i could help you.
Try just putting it into an array.
as that will be the variable the $_POST checks on the other side
and just checked your link, its teamName for the field
$fields = array("teamName"=>"julia");
Then..
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
So your complete code is...
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
$fields = array("teamName"=>"julia");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$output = curl_exec($ch);
var_dump($output);
curl_close($ch);
?>

Get destination URL of a link from edealinfo.co.uk in PHP

The URL that I'm working with is: http://www.edealinfo.co.uk/deals/redirect.php?id=k9OTxOWl25NiuN3KuZWIlFeagbK3aZo%3
I already tried:
$ch = curl_init("http://www.edealinfo.co.uk/deals/redirect.php?id=k9OTxOWl25NiuN3KuZWIlFeagbK3aZo%3");
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
print_r($data = curl_getinfo($ch));
echo $data["url"];
I also tried:
print_r(get_headers("http://www.edealinfo.co.uk/deals/redirect.php?id=k9OTxOWl25NiuN3KuZWIlFeagbK3aZo%3"));
Without any luck. Anyone has a solution?
That URL is not redirecting with a header, rather using an auto-submitting form in the returned HTML. This is why you're not having any luck with the headers.
Loading...<form action='/cgi-bin/amazonsp.cgi?B006U98G74' method='post' name='frm'></form><script>document.frm.submit();</script>
You'll need to parse the document body.

Categories