Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to log HTTP request?

    How can I log the http request sent by the following html form:

    Code:
    <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.
    Last edited by Dan06; 03-24-2009 at 07:50 PM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you want to see them for debugging or really want to log them as long as script run?

    best regards

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I want the HTTP request for debugging purposes.
    Last edited by Dan06; 03-24-2009 at 05:46 PM.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dan06 View Post
    I want the HTTP request for debugging purposes.
    write on the top of files_upload.php:
    PHP Code:
    print_r($_POST); 
    and remove when you finish.

    best regards

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by oesxyl View Post
    write on the top of files_upload.php:
    PHP Code:
    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):
    Code:
    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?

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dan06 View Post
    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):
    Code:
    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

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    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.

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dan06 View Post
    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

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    205
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •