PHP Classes

POST sent by Browser

Recommend this page to a friend!

      PHP Classes blog  >  File upload progress ...  >  All threads  >  POST sent by Browser  >  (Un) Subscribe thread alerts  
Subject:POST sent by Browser
Summary:Help required on getting text data from a browser
Messages:14
Author:Santosh Nagarajan
Date:2007-10-10 16:38:33
Update:2008-03-20 05:23:03
 
  1 - 10   11 - 14  

  1. POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-10 19:23:13
Hi Everybody,

I need help on how to capture data on a Apache Server (Linux) with PHP scripts. The requirement is :

A browser is sending data thru a POST request as "Line-based text data:" with MIME type as "application/x-www-form-urlencoded".

For example request sent by browser contains following data:

1000 Download Success\r\n
your id is :1kb@mycompany.com 1000 Success\r\n
10001 copy error \r\n
1002 error in download client \r\n

Above data is being sent to a php script hosted on a server. For example:
192.10.6.39/browsertest/html/test.p ...

Now, it is expected from the script on server i.e. "test.php" to capture 4 lines of data sent by the browser thru POST method (refer the data above).

Please help me by giving clues or sample line of code to achieve this.

Thanks in advance.

Mahesh Janardhan

  2. Re: POST sent by Browser   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-10 19:29:52 - In reply to message 1 from Santosh Nagarajan
I am not sure what you mean. The browser sends regular POST and GET requests. Doesn't $_POST and $_GET super-global variables have the request information you want?

  3. Re: POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-11 06:12:34 - In reply to message 2 from Manuel Lemos
Hi Manuel Lemos,

Thanks for your interest and quick reply.

No... I tried to capture the data with $_POST method but it is not getting me any piece of data for above mentioned case. Could you suggest me with few lines of sample code ? if I have done any mistake in my code I can correct.

Awaiting your response.

Thanks
Mahesh Janardhan

  4. Re: POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-11 06:12:54 - In reply to message 2 from Manuel Lemos
Hi,

One more information I would like to furnish. The browser is not sending above said data thru any FORM. In case of a FORM we know the data type and their respective variables. We can easily capture these kind of data by $_POST method. I too agree.

But this is not the case. The browser is just sending some plain text like data with above mentioned mime type. It is not associated with any FORM or any variable to capture. It is actually an output of certain process carried out by a customized browser. We need to pass on this data to another script for maintaining a log.

Best Regards
Mahesh Janardhan

  5. Re: POST sent by Browser   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-11 06:17:17 - In reply to message 4 from Santosh Nagarajan
If you are sending an AJAX request and you used content-type application/x-www-form-urlencoded your request body is malformed.

You need to encode the values properly before sending to the server as a correct POST request like it is sent by the browser for form submissions. Otherwise, PHP will ignore the submitted values.

  6. Re: POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-11 07:19:57 - In reply to message 5 from Manuel Lemos
No it is not AJAX request. It is a regular php POST request. The data being sent is in plain text format. But to be inline with certain standards, the browser is sending urlencoded MIME type along with the data.

OK.. let us look from a different angle. How to capture incoming stream of text data (which always varies in length) being received by a php script and dump it into a text file for further analysis?

  7. Re: POST sent by Browser   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-11 07:26:56 - In reply to message 6 from Santosh Nagarajan
Are you saying it is not a real browser but rather a PHP script emulating a POST request?

Anyway, you cannot send a HTTP request with content-type set to application/x-www-form-urlencoded if the request body is not url-encoded. If you do not do that, PHP will discard the POST data.

As a matter of fact sending malformed requests like you are doing may even trigger security alarms of the Web server owner and they may take preventive security measures to block future requests.

  8. Re: POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-11 07:27:33 - In reply to message 6 from Santosh Nagarajan
Sorry, one small correction in the above comment. Please read it as "It is a regular HTTP POST request"

  9. Re: POST sent by Browser   Reply   Report abuse  
Picture of Santosh Nagarajan Santosh Nagarajan - 2007-10-11 18:58:21 - In reply to message 7 from Manuel Lemos
It is a real browser. But it has a in-built download client, which handles a regular HTTP download and OMA download. OMA download will have a download descriptor file which gives details about the object being downloaded. Hence this download client is integrated part of the browser, I am referring it as browser.

What I mean by text data is that, even though the data is urlencoded it is in a readable format like 'plain/text'. Actually it is, indeed, urlencoded.

Certainly it is not intended to break any security measures. It is intended to download various types of objects onto client device and then send the feedback of the downloaded process on to a script (in my case it is test.php) to monitor statistics/status about the downloaded object.

  10. Re: POST sent by Browser   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-11 19:02:23 - In reply to message 9 from Santosh Nagarajan
The way you presented your sample values it is not correctly URL-encoded to be accepted as a request of content-type application/x-www-form-urlencoded . That is why PHP discards your request and the values do not appear in POST.

To make it work you must emulate a form POST request properly. So, it must be of the form:

name1=value1&name2=value2 etc...

Since all values are URL encoded, there must be no line breaks. Everything is in a single line.

 
  1 - 10   11 - 14