PHP Classes

$body in HTTP Client

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  $body in HTTP Client  >  (Un) Subscribe thread alerts  
Subject:$body in HTTP Client
Summary:Processing $body
Messages:11
Author:David Halliday
Date:2007-03-02 13:04:45
Update:2008-06-30 19:21:18
 
  1 - 10   11 - 11  

  1. $body in HTTP Client   Reply   Report abuse  
Picture of David Halliday David Halliday - 2007-03-02 13:04:45
Hello,

Is it at all possible to populate another variable with the value of $body? In the loop:-

for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!="" || strlen($body)==0)
break;
echo $body;
}

The above works fine for me and the page is retrieved. The only problem is that I can not echo a form at the top of the page BEFORE the $body is inserted (echoed). I have tried several things, e.g. placing the "echo form" just above the "echo $body" but it didn't work. Also, ob_start and ob_end_flush didn't do the trick.

How could one get the value of $body as a variable OUTSIDE the for loop?

Please note: that if one used "error_reporting(E_STRICT)" the script would work but the problem is that all the images + javascript files are retrieved in ascii format - they are not displayed correctly.

Thank you.
David

  2. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-02 19:48:18 - In reply to message 1 from David Halliday
Sure, just keep appending the body data to a separate variable like this:

for($data='';;)
{

$error=$http->ReadReplyBody($body,1000);

if($error!=""
|| strlen($body)==0)
break;

$data .= $body;
}

If the end, the $data variable holds all the data that was retrieved. This works also when you are retrieving binary data like images or Javascript files.

  3. Re: $body in HTTP Client   Reply   Report abuse  
Picture of David Halliday David Halliday - 2007-03-03 06:06:10 - In reply to message 2 from Manuel Lemos
Thank you. Yes, the new variable can now be placed outside the "for loop".

However, it doesn't solve the problem of displaying a form BEFORE the retrieved page is displayed . Correct me if I'm wrong: I think it is because wherever the $data is placed, one cannot echo anything * UNTIL ALL HEADERS * are sent and the files (images, css, js) have been retrieved ? (I don't understand though why ob_start() + ob_end_flush still don't solve the problem).

One possible solution would be to insert the retrieved page in an inline frame. The echoed form could go at the top then without any problem. From your experience : would that be the only solution?

David

  4. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-03 06:35:09 - In reply to message 3 from David Halliday
I am not sure what you are trying to do.

Anyway, you can send the headers retrieved from the server with the ReadReplyHeaders using the PHP Header() function. Then you output the response data retrieved from the server.

Take a look at the test_http_image_request.php to see a practical example.

  5. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Abdulkadir KUCUK Abdulkadir KUCUK - 2008-06-23 15:39:26 - In reply to message 3 from David Halliday
Dear Manuel Lemos;
Could you tell me how can get youtube video via php wth your client.
I want to use youtube videos with custom flv player and via proxy youtube videos.
I read your test_http_image_request.php example but there is a problem to find video url. other simple ereg based youtube download link generators can't get video from http clients outputs. How can I do this? Could you help me?
my e-mail: [email protected]

  6. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Abdulkadir KUCUK Abdulkadir KUCUK - 2008-06-23 16:14:30 - In reply to message 4 from Manuel Lemos
with your
for($data='';;)
{

$error=$http->ReadReplyBody($body,1000);

if($error!=""
|| strlen($body)==0)
break;

$data .= $body;
}
code I get one </html> sperated code and one original html code.
how can I get only not encoded html

  7. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-06-23 18:29:58 - In reply to message 5 from Abdulkadir KUCUK
I am not sure what you mean but I am afraid this has nothing to do with the HTTP client class.

You can retrieve a page with embedded YouTube player to extract the video URL. However, the actual Flash video stream is retrieved by the YouTube video player. You need to hack it to figure how to determine the Flash video stream URL in order to download it.

  8. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Abdulkadir KUCUK Abdulkadir KUCUK - 2008-06-23 19:53:36 - In reply to message 7 from Manuel Lemos
<?php
/*
* test_http.php
*
* @(#) $Header: /home/mlemos/cvsroot/http/test_http.php,v 1.18 2008/02/24 05:06:30 mlemos Exp $
*
*/

?>

<?php
require("http.php");
set_time_limit(0);
$http=new http_class;
$http->timeout=0;
$http->data_timeout=0;
$http->debug=1;
$http->html_debug=1;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$http->follow_redirect=1;
$http->redirection_limit=5;
$http->exclude_address="";
$http->prefer_curl=0;
$arguments["ProxyHostName"]="195.75.146.237"; //working
$arguments["ProxyHostPort"]=80;
....
.... bla bla bla..
$error=$http->Open($arguments);

if($error=="")
{

$error=$http->SendRequest($arguments);

if($error=="")
{


$data='';
for(;;){
$error=$http->ReadReplyBody($body,1000);

if($error!="" || strlen($body)==0)
break;
$pdata.= $body;
}
echo $pdata;

}
}
$http->Close();

?>

I browse http://localhost/proxy2/test_http.php?link=http://www.youtube.com/watch?v=tEJnVQuAPTw then it gives output below

S and C started lines.
...... encoded html
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01

......
&lt;/script&gt;<br />
<br />
<br />
<br />
&lt;/html&gt;<br />


Good html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
.....
......
GOOOD HTML I want only this part
.............
</html>Disconnected from www.youtube.com<br />

I want to get unblocked youtube video streams for custom flv players.

I hacked youtube video player is using only video id and t value it browses
youtube.com/get_video?video_id=$Vid ... this is url type
I will use this sytem in custom flv player embed script like this
s1.addVariable("file","http://www.youtubekaydet.com/proxy2/urlal.php?v=ggk3CLI_gNs");

  9. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-06-24 05:58:47 - In reply to message 8 from Abdulkadir KUCUK
I am not sure what you want. If you know how to determine the Flash video stream URL from the YouTube video page URL, I think you just need to retrieve the video stream directly instead of retrieving the video page URL.

  10. Re: $body in HTTP Client   Reply   Report abuse  
Picture of Abdulkadir KUCUK Abdulkadir KUCUK - 2008-06-30 18:49:05 - In reply to message 9 from Manuel Lemos
dersanalt.com/ytb is comleted with using http class modification. It works well. Now you can search youtube with http://www.dersanalt.com/ytb link. You can download youtube videos with http client class.

 
  1 - 10   11 - 11