Jump to content

PHP fopen www.google.com/search? Forbidden [WORKED AROUND]


openmp3

Recommended Posts

Hello,

 

On the features page of heliohost's php hosting the following is stated:

 

- We don't allow users to access files outside their allocated disk space. The security risk is pretty obvious here.

 

I understand the security risk in terms of being able to access other users' files, but I believe this is the reason why I cannot open url with fopen. As alternative I could use the curl library, but this has the disadvantage that first the complete html page needs to be loaded before you can read the information.

 

Is there something to do about this?

 

Kind regards,

opensoftwaredev

Link to comment
Share on other sites

As far as I know fopen still works. I didn't test it but you should use the php5 functions anyway. Much better and easier.

 

file_get_contents();

 

and

 

file_put_contents();

 

example:

$content = file_get_contents("$url");

file_put_contents("YOUR_FILE", "YOUR_CONTENT");

 

Go to php.net for more info.

http://php.net/manual/en/function.file-get-contents.php

 

Link to comment
Share on other sites

Thanks Byron for the reply, I wasn't aware of these functions yet, alltough they have the same functionality as curl, opening a complete file into a variable, which can take a long time if the page is big.

 

Next to that I'm not in doubt that fopen works, only when I try to open a url I get 0 response.

Link to comment
Share on other sites

Thanks Byron for the reply, I wasn't aware of these functions yet, alltough they have the same functionality as curl, opening a complete file into a variable, which can take a long time if the page is big.

 

file_put_contents and file_get_contents are taking the place of fopen and fwrite. There's no difference in the amount of time, not that I've noticed.

 

Next to that I'm not in doubt that fopen works, only when I try to open a url I get 0 response.

 

I just tested this on my site and it works fine:

 

<?php
$file = fopen("index.html","w");
fwrite($file, "<html><body bgcolor=\"blue\" text=\"white\">Hello World!</body></html>");
fclose($file);
?>

 

 

Link to comment
Share on other sites

I'm sure that would work since that is local. Maybe I should have been more specific with "url". I ment an external URL, like

www.google.com/search?filter=0&hl=en&num=50&start=0&q=asdf

 

On my local webserver this works, but not on heliohost (yet)

 

file_put_contents and file_get_contents are taking the place of fopen and fwrite. There's no difference in the amount of time, not that I've noticed.

PHP.net: fopen

fopen() binds a named resource, specified by filename , to a stream.

After this you can read the stream line by line with fgets() and execute code accordingly. This is diferent from

PHP.net: file_get_contents

Reads entire file into a string

where you have to walk trough your output string after the complete page was downloaded. Especially with huge open directories (which I also want to open) this takes way more time, believe me.

 

Thanks a lot for the effort of trying though! Could you try an external link for me?

Link to comment
Share on other sites

This works for me. Returns Google's source code.

 

http://byrondallas.heliohost.org/test/remote_file.php

 

<?php
if ($fp = fopen('http://www.google.com/', 'r')) {
$content = '';
while ($line = fread($fp, 1024)) {
$content .= $line;
}
$content = htmlspecialchars($content);
echo $content;
} else {
echo "An error occured when trying to open the specified url"; 
}
?>

 

Link to comment
Share on other sites

Thanks for demonstrating that, and you're right, it just works. The thing was that my script didn't give me the results I hoped for because of the following reason:

 

Google

Your client does not have permission to get URL /search?filter=0&hl=en&num=1&start=0&q=%22Simon%20and%20Garfunkel%22%20-%20%22Boxer%22 from this server. (Client IP address: *.*.*.* (no worries djbob))

 

I'll have to find another workaround for this one.

 

Thanks for the support Byron!

Link to comment
Share on other sites

So funny that it DOES work with CURL, but maybe in the future Google will block that too??

 

Anyway, now that it is working, maybe you can use it if you like:

 

http://openmp3.heliohost.org

 

It searches open-directories for mp3 and with help of javascript it makes a table of links in those directories, corresponding to the search query. It sorts the table on relevance.

Link to comment
Share on other sites

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.   Paste as plain text instead

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