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!
Strange characters in http output.
Moderator: General Moderators
tryyou will see that those values really are in the output of /new_listings.mv
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);
}
?>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
http://www.justmaui.com/ram_get3.php
Direct:
http://www.meyercomputer.com
do you refer to
That's the http-response header. Everything before the first blank line belongs to the header.
?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.
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…
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1Transfer-Encoding: chunked