FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-24-1999, 10:45 PM   Postid: 43274
pdstein
Registered User

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: May 1999
Posts: 242
fsockopen problem

I was experimenting with getting HTML from another website by opening a socket and echoing each line.  The strange thing is that while the echoed HTML looks nearly identical to the actual website, it seems to insert a few strange characters which screws up one image on the page.  Does anyone know what is causing this?

The script is at http://www.ourchurch.com/misc/

The script is:

Code Sample:

<?
$hostname = &quot;www.cypressmeadows.org&quot;;
$port = 80;
$uri = &quot;/&quot;;
$showline = 0;

$fpread = fsockopen(&quot;$hostname&quot;, $port, &amp;$errno, &amp;$errstr);

if(!$fpread) {
     echo &quot;$errstr ($errno)
\n&quot;;
} else {
     fputs($fpread,&quot;GET $uri HTTP/1.1\nHOST: $hostname\n\n&quot;
     while(!feof($fpread)){
          $line=fgets($fpread, 255);
          if (!$showline) {
               $showline = ereg(&quot;<HEAD>&quot;, $line);
          }
          if ($showline) {
               echo &quot;$line&quot;;
          }
     }
}
fclose($fpread);
?>




Using this code produces a line of HTML that has the broken image in it

Code Sample:
                <img src=&quot;
32
http://www.cypressmeadows.org/gif/menu/EmailUs.gif
d3c
&quot; border=0></A>



Where the actual website has no broken image:

Code Sample:
                <img src=&quot;http://www.cypressmeadows.org/gif/menu/EmailUs.gif&quot; border=0></A>


pdstein is offline   Reply With Quote
Old 10-26-1999, 10:16 AM   Postid: 43275
pdstein
Registered User

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: May 1999
Posts: 242
I seem to have stumped everyone...
pdstein is offline   Reply With Quote
Old 10-26-1999, 10:49 AM   Postid: 43276
Justin
Visitor
 
Justin's Avatar

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
I'm not sure why you are looking for the first <HEAD> tag... are there lines before the <HEAD> tag that you are wanting to exclude? If so, you might want to use eregi() unless you know for a fact that the <HEAD> tag is all caps...

Other than that I don't really see a problem... you might want to try this instead though:

############
$page = file (&quot;http://website.com&quot;
for ($i = 0; $i < count($page); $i++) {
   print &quot;$page[$i]&quot;;

}
############

The file() function returns the file/web page in an array, then we walk through the array. Better yet, let's reduce this to one line:

############
print (join (file (&quot;http://website.com&quot, &quot;&quot);
############

This fetches the page into an array, joins it with &quot;&quot; (because the newlines are still attached), and prints it out.

I still am not sure why your code above doesn't work though - it looks pretty much normal to me - maybe try it without sending a HOST header? (I've never used the HOST header - I just send the GET and it works for me)...

Hope this helps.

------------------
Justin Nelson
FutureQuest Support
Justin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 05:44 AM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.