Strange characters in http output.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Knuge
Forum Newbie
Posts: 4
Joined: Thu May 01, 2003 3:16 pm

Strange characters in http output.

Post by Knuge »

I am using PHP to GET and display a page. When I display the output, I am getting strange characters in the output.

Here is an example:
http://www.justmaui.com/ram_get.php?dbi ... 5&task=new
Under the “Main Page” link there is “fea” and “1000” that shouldn’t be there. Sometimes the characters show up in the middle of tags, like between the b and g of a bgcolor. This happens even calling plain html pages, and I’ve seen it in both ie6 and ns7.

The code:
<?php
$site = 'http://www.justmaui.com';

switch ($task) {

case "search":
$link = '/search.mv?dbid='.$dbid;
search($link,$site);
break;

case "new":
$link = '/new_listings.mv?days_back=7&dbid='.$dbid;
search($link,$site);
break;

default:
break;
}

function search($link,$site)
{
$fp = fsockopen('www.mauiboard2.com',80);
fputs($fp, "GET $link HTTP/1.1\r\n");
fputs($fp, "Host: http://www.mauiboard2.com\r\n");
fputs($fp, "Referer: $site\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "User-Agent: RAM-GET\r\n");
fputs($fp, "Connection: close\r\n\r\n");

while (!feof($fp))
{
$output .= fgets($fp,1024);
}
$output = str_replace('VALUE="justmaui.com"', 'VALUE=""', $output);
$output = str_replace('url=justmaui.com', 'url=', $output);
echo $output;
fclose ($fp);
}
?>

Thanks for any help!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
$site = 'http://www.justmaui.com';
$dbid = $_GET['dbid'];
$task = $_GET['task'];

switch ($task)
{
	case "search":
		$link = '/search.mv?dbid='.$dbid;
		search($link,$site);
		break;
	case "new":
		$link = '/new_listings.mv?days_back=7&dbid='.$dbid;
		search($link,$site);
		break;
	default:
		break;
}

function search($link,$site)
{
	$fp = fsockopen('www.mauiboard2.com',80);
	$request = "GET $link HTTP/1.1\r\n";
	$request .= "Host: http://www.mauiboard2.com\r\n";
	$request .= "Referer: $site\r\n";
	$request .= "Content-type: application/x-www-form-urlencoded\r\n";
	$request .= "User-Agent: RAM-GET\r\n";
	$request .= "Connection: close\r\n\r\n";
	echo '<fieldset><pre>', htmlentities($request), '</pre></fieldset>';
	fputs($fp, $request);
	
	$output = '';
	while (!feof($fp))
	{
		$output .= fgets($fp,1024);
	}
	$output = str_replace('VALUE="justmaui.com"', 'VALUE=""', $output);
	$output = str_replace('url=justmaui.com', 'url=', $output);
	echo '<fieldset><pre>', htmlentities($output), '</pre></fieldset>';
	fclose ($fp);
}
?>
you will see that those values really are in the output of /new_listings.mv
Knuge
Forum Newbie
Posts: 4
Joined: Thu May 01, 2003 3:16 pm

Post by Knuge »

I understand it’s in the output. What I don’t understand is why, and what I can do about it. Here’s another example, just pulling in my main site page. It’s got strange characters as well, but looks fine when pulled into a browser window…

http://www.justmaui.com/ram_get3.php

Direct:
http://www.meyercomputer.com
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

do you refer to
HTTP/1.1 200 OK Date: Fri, 02 May 2003 02:07:42 GMT Server: Apache/1.3.26 (Unix) mod_ssl/2.8.10 OpenSSL/0.9.6g FrontPage/5.0.2.2510 PHP/4.3.1 mod_throttle/3.1.2 P3P: CP="ALL DSP COR ADM PSA OUR BUS NAV" X-Powered-By: PHP/4.3.1 Set-Cookie: MeyerHostID=3eb1d2ee253d0; expires=Sat, 01-May-04 02:07:42 GMT; path=/; domain=.meyercomputer.com Connection: close Transfer-Encoding: chunked Content-Type: text/html d67
?
That's the http-response header. Everything before the first blank line belongs to the header.
Knuge
Forum Newbie
Posts: 4
Joined: Thu May 01, 2003 3:16 pm

Post by Knuge »

No, I understand the header, and can parse that out easy enough. It's the strange characters scattered throughout. For example, at http://www.justmaui.com/ram_get3.php the "198" on the upper left; the "19c" that's between the four tables in the middle of the page; the "19e" that puts itself between the b and the g of bgcolor in the td tag causing the first box of the four in the middle to be white, and the "0" at the bottom. They don't appear pulling the page into a browser, but do if I call with above code…
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:oops: I did not take a closer look at the output.
Transfer-Encoding: chunked
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
Knuge
Forum Newbie
Posts: 4
Joined: Thu May 01, 2003 3:16 pm

Post by Knuge »

Ahh! And changing the http to 1.0 keeps it from "chunking."

Thanks!
Post Reply