anonbux0 Posted September 28, 2013 Share Posted September 28, 2013 (edited) 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 September 28, 2013 by anonbux0 Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted September 28, 2013 Share Posted September 28, 2013 How about you give us the url to work with? Will help someone, to help you. Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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.. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted September 28, 2013 Share Posted September 28, 2013 You must be hitting the DDOS protection of CloudFlare, which means you or others are accessing the website too many times, so they are limiting your access. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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? Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 (edited) 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 September 28, 2013 by vinny42 Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 (edited) 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 September 28, 2013 by anonbux0 Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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? Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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 Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 Sounds like you haven't fixed it right :-) It should read: curl_setopt($ch, CURLOPT_URL, "https://example.com/a/token.php"); Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 Sounds like you haven't fixed it right :-) It should read: curl_setopt($ch, CURLOPT_URL, "https://example.com/a/token.php"); oh lol but it gives me the cloudflare response page :/ , i need to get the response after the cloudflare page.. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 wrong URL? Do you have to login or send cookies? Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 wrong URL? Do you have to login or send cookies? when the people make an account, that account will be logged in forever.. so, is not necessary to make login, because the people of that site already has made the login Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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? Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
anonbux0 Posted September 28, 2013 Author Share Posted September 28, 2013 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.. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 28, 2013 Share Posted September 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.