Jump to content

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
https://forums.phpfreaks.com/topic/282502-php-function-to-open-a-link/
Share on other sites

How about you give us the url to work with? Will help someone, to help you.

Humm.. sorry i can't :/ i only want to make a simple webpage with the php script that when a visitor visits my page, automatically open the link https://example.com/a/token.php and save the response of the page into a file.txt hosted in my hosting account.

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.

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

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.

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

 

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

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

Sounds like you haven't fixed it right :-)

 

It should read:

 

curl_setopt($ch, CURLOPT_URL, "https://example.com/a/token.php");

 

 

oh lol :D

 

but it gives me the cloudflare response page :/ , i need to get the response after the cloudflare page..

 


 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.

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?

 


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.

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

 


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.

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.