0

I have a web page that has the following code;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<title>Search results</title>
<?php
include_once('filename.php');
$info = ptb_connect('filename.csv','F');
$locations = ptb_listUnique($info, 'Property_Location');
$property_type = ptb_listUnique($info, 'Property_Type');
$property_buy_rent = ptb_listUnique($info, 'Buy_Rent');

if(empty($_GET['location']) && empty($_GET['type']) && empty($_GET['buyrent']) && empty($_GET["min_val"]) && empty($_GET["room_no_min"])){
header("Location:propertysearch.php"); exit;
}

But when I go to the page rather than redirecting to propertysearch.php I get the message "Warning: Cannot modify header information - headers already sent by (output started at N:\www\test\results.php:7) in N:\www\test\results.php on line 15" which is the line that begins Header("Location..

I have tried many things to try and resolve this, including eliminating white spaces, using ob_start(); etc but can not figure it out.

All help is greatly appreciated.

DonOfDen
  • 3,968
  • 11
  • 62
  • 112
Naz
  • 900
  • 2
  • 10
  • 25

2 Answers2

3

I hope this answer might help you:

To use a header it has to be used before any output has started on the page. In other words it has to come before anything is printed including the docytype.

The syntax to use is very simply at the very top of the file open php then then type ob_start() this turns out output buffering:

<?php ob_start(); ?>

Now you can call a header function anywhere within your page. To make sure you clear resources that are not being used at the very bottom of your file flash the buffer by typing ob_flush() inside php:

<?php ob_flush(); ?>

This worked for me when I faced some issues.! Hope this will help you too..

DonOfDen
  • 3,968
  • 11
  • 62
  • 112
1

I managed to solve this, it was Byte Order Mark issue, I changed the character set from UTF-8 to ISO Western Europe and that solved it.

Naz
  • 900
  • 2
  • 10
  • 25