View Full Version : View an external pages source code?
danielwarner
04-27-2007, 03:27 PM
is it possible?
for example if i were to want to view google.com's source code then i could possibly display the html on my page?
Thanks for any help
napster
04-27-2007, 03:34 PM
Right click > view source.
danielwarner
04-27-2007, 03:42 PM
in php?
iLLin
04-27-2007, 05:32 PM
file_get_contents()
danielwarner
04-28-2007, 04:49 PM
is there any reason this would not work for me?
Any methods around it?
CFMaBiSmAd
04-28-2007, 05:10 PM
is there any reason this would not work for me?What errors or other symptoms did you get?
Any methods around it?CURL and fsockopen.
danielwarner
04-28-2007, 06:43 PM
ive had a go at curl and i got the same result (loading for ages before timing out) whats fsockopen? will it do the same thing?
rafiki
04-28-2007, 08:03 PM
hmm on my local machine which is very **** it runs file_get_contents() with ease!
<?php
file_get_contents("http://www.google.com/search?q=file_get_contents+php");
?>
danielwarner
04-29-2007, 12:06 AM
yeah i dont know my hosts problem but it just wont work. i also tried a few free hosts (php 4.5+) and it still didnt work. as far as im aware this was implemented 4.3~ish?
I dont have php on my local comp though. (never got round to installing it)
This couldnt possibly be a browser issue could it? (my host uses php 4.13 or something)
CFMaBiSmAd
04-29-2007, 01:14 AM
The allow_url_fopen setting will prevent the file functions that allow http requests, but there will be a warning error if they fail. Check your web server log files and/or turn on full error_reporting() in your script.
The curl functions should work as long as they are enabled/loaded. Again, check your web server log file for errors and/or turn on full error_reporting() in your script.
If nothing works on different servers is it likely a user error and you would need to post your code to get specific help with it.
danielwarner
04-29-2007, 05:08 PM
I dont think its a user error other people have used scripts and posted them and they still wouldnt work for me...
I have decided to install php locally as i dont actually need this script live on the internet. (i suppose i have more controls over it this way). - Idea from rafiki
danielwarner
04-29-2007, 05:27 PM
Error: Fatal error: Call to undefined function: file_get_contents() in c:\phpdev\www\phpinfo.php on line 2
Code: (from php.net)<?
$content=file_get_contents("http://www.google.com",FALSE,NULL,0,20);
echo $content;
?>
This is in my local host. Any reason this might be happening? Do i need to switch anything on for it to work? (and how would i do it)
rafiki
04-29-2007, 06:58 PM
im pretty sure it works as installed (atleast with XAMPP) im not sure about using the param's i just use get_file_contents("http://localhost/index.php"); or what not and if you want to echo the source code of a file dont forget to use htmlspecialchars()
http://uk2.php.net/htmlspecialchars
danielwarner
04-29-2007, 10:17 PM
Yippee! i uninstalled apache and php and all the bad stuff i had installed previously and i installed XAMPP and it works!!
Thanks rafiki! its a good program too :p
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.