I want to use sci-hub.cc to download scientific papers, but it is in russian and it is not easy to use.
It has a textfield for enter DOI or paper link.
Now, I want to make a website that, when users insert paper link, send this link to sci-hub as a query and then download it. How can I do this in php?
Thanks a lot.
i dont know how your page is working but what you looking for is a "POST" Request with.
The code below "does" the same if you type in something in the field on your page:
<php
$url = 'http://sci-hub.cc/';
$data = ['Request'=>'TEXT FOR FIELD'];
$options = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header'=> "Content-Type: application/x-www-form-urlencoded \r\n")
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
?>
Related
I want to read an external site after submit code with captcha. But using (PHP) file_get_contents the captcha is loaded 2 times, so its wrong.
The Form load an image to solve the captcha and sent via POST to the original site that show the result. Normally I solve the captcha and than, in the new site, I read (with my eyes) the content.
Now I want to let PHP read the content. I always solve first the captcha (in my page) and than send it to the other site and let (php) "file_get_contents" read the content.
HERE MY CODE..
<?php
$captcha = $_POST["captcha"];
?>
<html>
<form method="post" action="(this page)">
<img src="remote-captcha"><input type="text" name="captcha">
<submit>
<?php
$postdata = http_build_query(
array(
'captcha' => $captcha
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.form-page', false, $context);
$search = '/<div class="myclass">(.*)<\/div>/';
preg_match($search, $result, $show);
echo $show[0];
?>
At this point the form is loaded 2 times so the captcha is wrong.
Can someone help me?
I have application which post data to another site(running other application) with API link, and now I need returned feedback like "Application started!" or "error".. I tried to control variable $result but It returns me nothing. Application is started and everything works fine if I visit link with posted results.
If I visit API link manually, it just give me blank page(runned).
proces.php
<?php
if(isset($_POST['submit'])) {
$ssId = $_POST['ssId'];
$red = $_POST['red'];
$id = $_POST['id'];
$user = $_POST['user'];
$postdata = http_build_query(
array(
'ssId' => $ssId,
'red' => $red,
'id' => $id,
'user' => $user
)
);
$opts = array('http' =>
array(
'user' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://apiLink.com/someKey&ssId='.$ssId.'&red='.$red.'&id='.$id.'&user='.$user.'', false, $context);
header("Location: startApp.php");
}
?>
Problem is your current code handles request using $_POST however links trigger http 'GET' method instead of 'POST', also you have some additional checks like $_POST['submit'], hence links redirect fails to work with your logic.
If you replace $_POST with $_REQUEST then things should work with links as well provided you send all the relevant parameters along with it. Other option is just give a button enclosed in form with hidden input fields.
I am trying to call a web service which basicaly looks like this:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'
So this is how i call this web service:
$endpoint = "http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'";
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'Content-type: application/xml'
)
);
$context = stream_context_create( $opts );
$result = file_get_contents( $endpoint, false, $context );
$xml_result = simplexml_load_string( $result );
echo $xml_result->success;
So here, i got nothing, the xml_result is empty. And here is the interesting part - when i remove the blank space from the description:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Somedescription'
Everything is just fine, I got the answer from the web service. Also tried to call the web service with the chrome rest client WITH the blank space in the description and everything is OK, i have response. So this leads me to some kind of PHP problem here with the blank spaces in the web service. Please, help !
UPDATE:
print_r($result)
results in
1
This is not a valid URL, spaces must be escaped:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some%20description'
You might want to take a look at How to properly URL encode a string in PHP?.
I have the following code:
<?php
$ids = 'ids=com.hugogames.hugotrollwars';
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $ids
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://play.google.com/store/xhr/getdoc', false,
$context);
$convert = explode("\n", $result);
Basically its pulling permissions from the Playstore and displaying it as a string. The issue I am having is removing the un needed data (image links, description) and only show the permissions and the permissions description. I tried using the json_decode function with php and it returned NULL.
Is there something i'm missing?
Any help is greatly appreciated!
$result is not valid json. Google Play API is using a protobuf variant.
http://www.segmentationfault.fr/publications/reversing-google-play-and-micro-protobuf-applications/
There are also php libraries to talk to google play.
https://github.com/splitfeed/android-market-api-php
https://github.com/thetutlage/Google-Play-Store-API
I'm retrieving a PHP file using file_get_content(), cURL() or fopen() all return PHP code itself. It's not retrieving just the HTML code itself that PHP is outputting. How can I overcome this please?
It's basically generating an HTML newsletter preview for my customer that is generated from their CMS. However I want them to be able to copy and paste the HTML it generates into Mailchimp or such like. It just fetches the entire PHP source code though as well as the HTML :(
Hope you can help.
Thanks in anticipation.
Pete
Trying to read a local PHP file will return its source code, since its a "local" file, and is not parsed by the server.
If you wish to read the result of the PHP file you must request it from the server.
Meaning instead of doing:
$data = file_get_contents('x.php');
You should be doing
$data = file_get_contents('http://mysite.com/path/x.php');
Which will be parsed in the server, and then returned to you.
Cheers! :)
Shai.
This will work in localhost. Try this one: $url = "http://localhost/box.php";
function isAllBoxContents($boxid,$pageNum)
{
$postdata = http_build_query( array('myBoxid' => "$boxid", 'isAllBoxContents' => "all",'pageNum' => "$pageNum",'innerReq' => true ));
$opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ));
$context = stream_context_create($opts);
$url = "http://localhost/box.php";
$result = file_get_contents( $url, false, $context);
$cacheFileName = "isAllBoxContents".$boxid.$pageNum;
cacheMe($cacheFileName,$result);
}