PHP Classes

can't use header() after use http protocol client class

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  can't use header() after use http...  >  (Un) Subscribe thread alerts  
Subject:can't use header() after use http...
Summary:how can i use header() function after use package HTTP protocol
Messages:11
Author:chichi
Date:2007-09-10 02:53:32
Update:2008-04-30 02:14:22
 
  1 - 10   11 - 11  

  1. can't use header() after use http...   Reply   Report abuse  
Picture of chichi chichi - 2007-09-10 02:53:32
hi,

in the example code: test_http.php

<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos' PHP HTTP class</TITLE>
</HEAD>
<BODY>
<H1><CENTER>Test for Manuel Lemos' PHP HTTP class</CENTER></H1>
<HR>
<UL>
<?php
require("http.php");

/* Uncomment the line below when accessing Web servers or proxies that
* require authentication.
*/
/*
require("sasl.php");
*/

set_time_limit(0);
$http=new http_class;

/* Connection timeout */
$http->timeout=0;

/* Data transfer timeout */
$http->data_timeout=0;

/* Output debugging information about the progress of the connection */
$http->debug=1;

/* Format dubug output to display with HTML pages */
$http->html_debug=1;




......
......
......

for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
echo $header_name.": ".$headers[$header_name][$header_value],"\r\n";
}
else
echo $header_name.": ".$headers[$header_name],"\r\n";
}
echo "</PRE>\n";
flush();

echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n";
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
echo HtmlSpecialChars($body);
}
echo "</PRE>\n";
flush();
}
}
$http->Close();

/***** I ADDED THIS CODE *****/

ob_clean();
header("Location: http://www.php.net");

/*****************************/


it will show error:
Warning: Cannot modify header information - headers already sent in /path/test_http.php on line 216

how can i fix this error?
how can i edit the header or redirect to other page by using header() function after i get or read the response header?

Thanks for helping....

  2. Re: can't use header() after use http...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-09-10 03:15:01 - In reply to message 1 from chichi
You need to set the debug class variable to 0 to tell the class to not output debug information before you send your HTTP headers.

  3. Re: can't use header() after use http...   Reply   Report abuse  
Picture of chichi chichi - 2007-09-10 03:57:31 - In reply to message 2 from Manuel Lemos
i had set :
/* Output debugging information about the progress of the connection */
$http->debug=0;

/* Format dubug output to display with HTML pages */
$http->html_debug=0;

$http->debug_response_body = 0;


but the result still same.
Warning: Cannot modify header information - headers already sent in /path/test_http.php on line 217

Thanks for helping...

  4. Re: can't use header() after use http...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-09-10 04:18:05 - In reply to message 3 from chichi
That is because you still have several echo statements in the test_http.php script before the lines you have the Header() call.

The original script only has those statements for demonstration purposes. I think you do not need them there. Just remove those echo statements.

  5. Re: can't use header() after use http...   Reply   Report abuse  
Picture of chichi chichi - 2007-09-10 04:33:55 - In reply to message 4 from Manuel Lemos
hmmm, actually i had use http.class to write another class.

include_once("http.class.php");

class http_header{

var $vtkturl = "https://www.myurl.com/verify_ticket?v=1&";
var $error = "";

//get ticket code, pass the ticket code
function getTktResp($passid,$tktcode){
$http = new http_class;
$http->follow_redirect=1;
$http->debug_response_body=0;
$http->debug=0;
$http->debug_html=0;
$fc = new functions();
$this->error = $http->GetRequestArguments($this->vtkturl."pssid=".$passid."&tkt=".$tktcode, $arguments);
$arguments["Headers"]["Pragma"] = "nocache";
flush();
$this->error = $http->Open($arguments);
flush();
$this->error = $http->SendRequest($arguments);
flush();
$headers=array();
$this->error=$http->ReadReplyHeaders($headers);
if($this->error==""){
if ($http->response_status != 200) {
flush();
header("Location: http://www.url.com/error.php");
}
for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
{
$header_name=Key($headers);
if(GetType($headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
$array[$header_name]=$headers[$header_name][$header_value];
}
else
$array[$header_name]=$headers[$header_name];
}
flush();
}
$http->Close();
if ($array[s] != 1) {
flush();
header("Location: http://www.url.com/error.php");
}
else
return $array;

}
}



it only will show the header already sent error after used http.class, the other pages didn't got this error.
i had comment or delete all echo, print, print_r, print_f .... but it still cannot work...

Thanks for kindly helping....

  6. Re: can't use header() after use http...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-09-10 05:19:21 - In reply to message 5 from chichi
The error tells you the exact line on which something was outputted. You need to make sure that the Header() call happens before that line.

  7. Re: can't use header() after use http...   Reply   Report abuse  
Picture of chichi chichi - 2007-09-10 06:22:55 - In reply to message 6 from Manuel Lemos
i found the error come from flush();

if comment all flush(); it work properly~

^_^

  8. Re: can't use header() after use http...   Reply   Report abuse  
Picture of pijush pijush - 2007-09-10 07:59:10 - In reply to message 7 from chichi
test

  9. Re: can't use header() after use http...   Reply   Report abuse  
Picture of pijush pijush - 2007-09-10 08:00:30 - In reply to message 8 from pijush
test123

  10. Sender Email   Reply   Report abuse  
Picture of Jengkal Pete Jengkal Pete - 2008-04-29 21:57:18 - In reply to message 9 from pijush
How to send email from "My Name" <[email protected]> ?
Thank You

 
  1 - 10   11 - 11