views:

56

answers:

4

hi,

i'm using a php script for redirection after detecting the search word to my websiter from the search engines .

and my redirection code is working fine

but for some keywods i wat to stay in the same page. for that lines of code i'm getting a warning message in that pages.

Warning:  headers already sent 
          (output started at /home/friendsj/public_html/index.php:2) in
          /home/friendsj/public_html/index.php on line 20

below is the code i used in that pages

$ref=$_SERVER['HTTP_REFERER'];

if(strstr($ref,"test")){ 
  $url="http://www.howtomark.com/robgoyette.html";
}
else if(strstr($ref,"mu+word+gmail")){
    $url="http://www.howtomark.com/marketbetter.html";
}
else{
  if(strstr($ref,"how+to+market+better")){
  }    
}

if($url !=""){
  header("Location:$url");
}
A: 

remove any output started at the 2nd line at index.php

zerkms
+1  A: 

Redirections are accomplished by setting an HTTP header, as the use of the header() function suggests. That means that you can only redirect before you start the document output. Whatever you start printing on line 2, do it later ;-)

Álvaro G. Vicario
Thanksssssssssssssssssss
tibin mathew
A: 

If you are using the Header function you are not allowed to output something before that function is called.

In you case you wrote in line 2 on index.php something to output.

A bad workaround is to use the output cache functions ob_start. but this is not a real solution.

Bernd Ott
Why are output cache functions not a real solution?
Manos Dilaverakis
@Manos: because the better is to cure disease, and not just hide symptoms
zerkms
Dr. zerkms is in Wrong Community, We need a coder to explain :)
OM The Eternity
@zerkms The "disease" is unavoidable in larger applications, especially OO frameworks, where you have no idea what/when controllers might try to do. Using output buffering is a perfectly acceptable strategy. In fact it's often unavoidable.
Manos Dilaverakis
@Manos Dilaverakis: 1. he has 10 lines script. 2. OO frameworks always use ideology of chain of responsibility/intercept filters/request-response - so we NEVER EVER could do direct echo, because we have "response" object to interact to user. the ob_* is perfectly ugly and lame strategy
zerkms
@Parth: i speak english weakly and i might say what i think wrongly but don't you agree with me? ;-)
zerkms
@zerkms i think you are right. cure it!
Bernd Ott
@zerkms When I talk about output buffering in OO frameworks I am referring to the framework itself (the core), not the code written by the framework adopters.
Manos Dilaverakis
the last step within a framework is rendering. sure sometimes they are also using ob_cache functions. but they never use ob_cache to avoid problems with header()
Bernd Ott
A: 
sonill