openmp3 Posted December 16, 2009 Posted December 16, 2009 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 Quote
Byron Posted December 16, 2009 Posted December 16, 2009 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 Quote
openmp3 Posted December 16, 2009 Author Posted December 16, 2009 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. Quote
Byron Posted December 16, 2009 Posted December 16, 2009 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); ?> Quote
openmp3 Posted December 16, 2009 Author Posted December 16, 2009 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? Quote
Byron Posted December 16, 2009 Posted December 16, 2009 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"; } ?> Quote
openmp3 Posted December 17, 2009 Author Posted December 17, 2009 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! Quote
Byron Posted December 17, 2009 Posted December 17, 2009 You could use curl, but you said you didn't really want to go that route. Source of /search?filter=0&hl=en&num=1&start=0&q=%22Simon%20and%20Garfunkel%22%20-%20%22Boxer%22 http://byrondallas.heliohost.org/test/CURL_COOKIE.php Quote
openmp3 Posted December 19, 2009 Author Posted December 19, 2009 Thanks mate! I'll try to find another host where it is possible, which I probably won't find for free, and then I will modify my code using CURL. Quote
openmp3 Posted December 20, 2009 Author Posted December 20, 2009 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. Quote
Byron Posted December 20, 2009 Posted December 20, 2009 So funny that it DOES work with CURL, but maybe in the future Google will block that too?? I thought you knew that after I posted this link showing the source of that search? http://byrondallas.heliohost.org/test/CURL_COOKIE.php btw, nice work. Seems to work great and it's fast too! Quote
openmp3 Posted December 21, 2009 Author Posted December 21, 2009 Yes of course, I believed you, but I was stubborn Quote
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.