Jump to content

PHP function to open a link?


anonbux0

Recommended Posts

hey,

What php function can i use to open a link like, https://example.com/a/token.php ?

 

and save the response into a file in my host. (people.txt)

I have tried with fopen, but it doesn't work, doesn't give me the test.php response. 

ps: the test.php response is in plain text.

EDIT: The website is using cloudFlare, and before to see the test.php file, we have to wait 5 seconds. So, i need a file that bypass the cloudflare and send me the test.php source.

 

My script:

 

<?php

$handle = file_get_contents("https://example.com/a/token.php");

$file = fopen('people.txt', 'a');

$filtered = explode('"', $handle);
fwrite($file, $filtered[1]);

?>

 

Thank you! 

Edited by anonbux0
Link to comment
Share on other sites

If you google this for three seconds, you'll find a ton of references to the "cURL" functions. They are the only ones that do this correctly. fopen() etc require that the admin has enabled http wrappers, which is usually not desirable because of security issues.

the problem is that the website is using cloudflare..

Link to comment
Share on other sites

Which website, yours or the remote site?

And which of  the many meanings of the word "cloudflare" do you mean?

 

And how does using this cloudflare stop you from using cURL?

Can you send me a script in cURL that is able to read a response of one website, and then save it into a file hosted in my hosting? I need to get the response of this site https://example.com/a/token.php and then save it into my file.txt . like:

 

A person visit my page -> click on anything like an image -> after clicking, *automatically will navegate to url (http://www.example.com/a/token.php) -> get the content of the page -> and store in a file.txt in my host.* The part in * * has to be hidden.

Link to comment
Share on other sites

Well, Normally I'd flame you for not RT-ing the F'ing M, but because it requiers only two lines of extra code in the manual's first example:

 

<?php// create a new cURL resource$ch = curl_init(); // set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL, "http://forums.phpfreaks.comcurl_setopt($ch, CURLOPT_HEADER, false); // make curl_exec() return the data instead of printing it.curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL and pass it to the browser$strFetchedHTML = curl_exec($ch);// write the data to a filefile_put_contents('/tmp/junk.html', $strFetchedHTML); // close cURL resource, and free up system resourcescurl_close($ch);?>
Edited by vinny42
Link to comment
Share on other sites

 

Well, Normally I'd flame you for not RT-ing the F'ing M, but because it requiers only two lines of extra code in the manual's first example:

 

<?php// create a new cURL resource$ch = curl_init(); // set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL, "http://forums.phpfreaks.comcurl_setopt($ch, CURLOPT_HEADER, false); // make curl_exec() return the data instead of printing it.curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL and pass it to the browser$strFetchedHTML = curl_exec($ch);// write the data to a filefile_put_contents('/tmp/junk.html', $strFetchedHTML); // close cURL resource, and free up system resourcescurl_close($ch);?>

 

sorry, but that don't works :/ 

 

using:

 

<?php
// create a new cURL resource
$ch = curl_init();
 
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://example.com/a/token.php
curl_setopt($ch, CURLOPT_HEADER, false);
 
// make curl_exec() return the data instead of printing it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
// grab URL and pass it to the browser
$strFetchedHTML = curl_exec($ch);
// write the data to a file
file_put_contents('people.txt', $strFetchedHTML);
 
// close cURL resource, and free up system resources
curl_close($ch);
?>
 
I didn't got anything into people.txt file
Edited by anonbux0
Link to comment
Share on other sites

I trust that you did fix my copy/paste error in the  URL line? :-)

 

And of course you have now looked at the curl extension and you have looked at it's errorhandling functions etc so you can see why the request is failing?

 

Yes i changed it xD

 

I get this error:

 

Parse error: syntax error, unexpected $end in /home/............../public_html/test.php on line 19

Link to comment
Share on other sites

 


 so, is not necessary to make login, because the people of that site already has made the login

 

So you do have to login. cURL is not your browser, you have never logged in through cURL so cURL doesn't send any credentials to the remote site.

It's up to you to make cURL login to the remote site and send the right cookies etc along.

Link to comment
Share on other sites

So you do have to login. cURL is not your browser, you have never logged in through cURL so cURL doesn't send any credentials to the remote site.

It's up to you to make cURL login to the remote site and send the right cookies etc along.

 

humm., and is possible to make a script that when the people visits my page,  automatically uses the visitor cookies and get the content of the visitor target site?

Link to comment
Share on other sites

 


humm., and is possible to make a script that when the people visits my page,  automatically uses the visitor cookies and get the content of the visitor target site?

 

No, because the cookies that the remote site has set on your visitor's browsers are never sent to your website. And even if they were, there's probably some IP check done on the data so your site would be assumed to be a hacker.

Link to comment
Share on other sites

No, because the cookies that the remote site has set on your visitor's browsers are never sent to your website. And even if they were, there's probably some IP check done on the data so your site would be assumed to be a hacker.

humm.. but i can make a request asking for the visitor cookies, and send all cookies to my website..

Link to comment
Share on other sites

 


humm.. but i can make a request asking for the visitor cookies, and send all cookies to my website..

 

How would you suggest asking a browser to send all it's cookies when it is specificallty programmed to never ever do that? :-)

 

You might be better of trying oAuth, then your visitors could authorize you to see some of their data on the remote site, if that site also uses oauth.

 

But I'm affraid that you'll just have to live with the fact that you can't see data that is not meant for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.