...

View Full Version : Resolved How to log HTTP request?



Dan06
03-24-2009, 05:38 PM
How can I log the http request sent by the following html form:


<form method="post" enctype="multipart/form-data" action="files_upload.php">
Send these files:<br />
<input name="imgFile[]" type="file" /><br />
<input name="imgFile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>

Thanks.

oesxyl
03-24-2009, 05:40 PM
you want to see them for debugging or really want to log them as long as script run?

best regards

Dan06
03-24-2009, 05:44 PM
I want the HTTP request for debugging purposes.

oesxyl
03-24-2009, 05:51 PM
I want the HTTP request for debugging purposes.
write on the top of files_upload.php:


print_r($_POST);

and remove when you finish.

best regards

Dan06
03-24-2009, 06:10 PM
write on the top of files_upload.php:


print_r($_POST);

and remove when you finish.

best regards

Thanks for the suggestion, but unfortunately, it does not work. I added print_r($_POST) to the top of files_upload.php, but the printed array was empty - i.e. Array()

Following is files_upload.php with print_r($_POST):

print_r($_POST);

$targetPath = "images/";

for ($i = 0; $i < count($_FILES['imgFile']); $i++){
if (file_exists($_FILES['imgFile']['tmp_name'][$i])){
$targetPath = $targetPath . basename($_FILES['imgFile']['name'][$i]);
move_uploaded_file($_FILES['imgFile']['tmp_name'][$i], $targetPath);
}
}

//print_r($_FILES['imgFile']);

?>

Any suggestions?

oesxyl
03-24-2009, 06:15 PM
Thanks for the suggestion, but unfortunately, it does not work. I added print_r($_POST) to the top of files_upload.php, but the printed array was empty - i.e. Array()

Following is files_upload.php with print_r($_POST):

print_r($_POST);

$targetPath = "images/";

for ($i = 0; $i < count($_FILES['imgFile']); $i++){
if (file_exists($_FILES['imgFile']['tmp_name'][$i])){
$targetPath = $targetPath . basename($_FILES['imgFile']['name'][$i]);
move_uploaded_file($_FILES['imgFile']['tmp_name'][$i], $targetPath);
}
}

//print_r($_FILES['imgFile']);

?>

Any suggestions?
you must print_r $_FILES not $_POST. I didn't look to your form, just answer to your question, :)

best regards

Dan06
03-24-2009, 07:05 PM
you must print_r $_FILES not $_POST. I didn't look to your form, just answer to your question, :)

best regards

Thanks for the suggestions. I tried print_r($_FILES) earlier and that shows me the content of the $_FILES array. But I'm interested in the actual HTTP Request Entity. Following is an example of an HTTP request entity log from one of my java codes, can this type of "log" be done in php? Thanks.


HttpConnection - Open connection to xxx.xxx.xxx.xxx:80
header - >> "POST /utilist/files_upload.php HTTP/1.1[\r][\n]"
HttpMethodBase - Adding Host request header
header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
header - >> "Host: xxx.xxx.xxx.xxx[\r][\n]"
header - >> "Expect: 100-continue[\r][\n]"
header - >> "Content-Length: 839[\r][\n]"
header - >> "Content-Type: multipart/form-data; boundary=XWrcb9F1Ockoh2pAAUTtE2gA4UDREN__KbJ[\r][\n]"
header - >> "[\r][\n]"
header - << "HTTP/1.1 100 Continue[\r][\n]"
header - << "HTTP/1.1 100 Continue[\r][\n]"
header - << "[\r][\n]"
HttpMethodBase - OK to continue received
content - >> "--"
content - >> "XWrcb9F1Ockoh2pAAUTtE2gA4UDREN__KbJ"

I'm specifically interested in the boundaries of the http request created by the html form.

oesxyl
03-24-2009, 07:16 PM
Thanks for the suggestions. I tried print_r($_FILES) earlier and that shows me the content of the $_FILES array. But I'm interested in the actual HTTP Request Entity. Following is an example of an HTTP request entity log from one of my java codes, can this type of "log" be done in php? Thanks.



I'm specifically interested in the boundaries of the http request created by the html form.
print_r($_SERVER), :)

I guess this will help you:

http://www.php.net/manual/en/reserved.variables.php

there are a lot of variable you can output, :)

Also you have another option. There is a firefox extension, firebug which will help you also with javascript, request header, very usefull for ajax.

best regards

Dan06
03-24-2009, 07:49 PM
Thanks for the help, I appreciate it. I used print_r($_SERVER) and a firefox add-on, "HttpFox," to get the request entity info I needed.

Best,
Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum