Forum Moderators: coopster

Message Too Old, No Replies

Unable to get source code for external websites

Probably need to reconfigure something as code is pretty simple

         

dougmcc1

4:39 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



I have Sokkit installed on a windows xp machine. I want to parse the html code of an external website but it doesn't look like php is connecting to any website I try. Here's the code I'm using.

$html=strtolower(implode('',file("http://www.yahoo.com")));
echo $html;

Is there some kind of configuration I have to make? The computer is on a network which is protected by a firewall, would that also have anything to do with it?

Thanks.

Timotheos

12:11 am on Dec 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Never heard of Sokkit before. Why pay though when you can get XAMPP [apachefriends.org] for free?

Anyway, you might have to change the fopen_wrappers setting [ca.php.net]. I find it so much nicer to use file_get_contents [ca.php.net].

Tim

dougmcc1

7:30 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



I tried file_get_contents() instead of file() and that didn't work. Also within php.ini allow_url_fopen was set to "on" and I changed it to "1" since that's what it shows here [ca.php.net...] but the script still isn't retreiving the html code.

Any other ideas?

coopster

10:19 pm on Dec 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you receiving any errors? Do you have error_reporting() turned up?

dougmcc1

10:40 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



I have error reporting turned on and using the following code I didn't receive any error messages, but I also received no output:

$url= 'http://www.msn.com';
$conn = fopen($url, "r");
$html = file_get_contents($url);
fclose($conn);
echo "HTML is:<BR><BR> $html";
die();

<added>
When I launch internet explorer I have to log in through a Novell login page before I can start browsing web pages. Is there somewhere I need to specify this username and password within php.ini or something?
</added>

coopster

11:07 pm on Dec 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That certainly sounds like your issue then. It sounds to me like you may very well have an internal network issue to overcome first.

With file_get_contents() you do not need to fopen() and fclose(), by the way.

dougmcc1

11:23 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



So can anyone here help with this or do I need to contact our IT department? I'm just wondering if there's something in php.ini or similar file that I can edit to fix the issue or if it's something I dont have control over. just knowing it's a network issue doesnt help much, I'd like to get a better understanding of how to go about fixing it.

Thanks for the replies so far.

coopster

7:25 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are correct in that this is a very simple operation and should be working just fine. If no errors are showing up, there isn't anything you can possibly do in the config to get it working beyond where it is at. I would check with the IT folks to see if they are blocking or if any errors are showing up first. If the server is running internally, try retrieving an internal web page first, unless of course you have to log in to get to that server too.

Anyango

7:43 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for 100% same operation, i use 100% different code. you might want to give it a try as well.

ob_start();
$page="http://wheretograbhtmlcodefrom"
include $page;
$data=ob_get_contents();
ob_clean();

echo $data;

;)

dougmcc1

8:10 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



Yeah I have 4 different coding examples that all work when I try grabbing the HTML source code of other pages on the internal website.

So while the code is working, PHP is unable to retreive HTML source code from websites outside of the network.

Any idea how to get Novell to let PHP out?

Anyango

8:17 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although, this could be a vague fluke but this could be it as well.

Your Php Parser may be blocked out-of-network access by your firewall and whenever it tries to grab html from an external website your firewall blocks it?

dougmcc1

8:30 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



Yeah isn't that what Novell is? Either way, how do I open up the firewall to let PHP through? When browsing the internet I go to a Novell login screen so I can access the web. How do I get PHP to do the same thing?

Timotheos

11:58 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I not sure but I think a proxy might help in this case.
[whitefyre.com...]