Welcome Guest, Not a member yet? Register   Sign In
When sending form data via post method, lighthttpd returns GET method
#1

[eluser]christoz[/eluser]
Hello i've deployed CI 2.1.2 on lighthttpd server, i've found something strange, “strange” because i have no explanation so far, i’m trying to send form data using a POST method, i check what is the type of method using the “$_SERVER[‘REQUEST_METHOD’]” into the target controller specified in the action attribute of the form, and the server responses GET method, The form is set to send at POST array not GET.
#2

[eluser]skunkbad[/eluser]
Maybe there is something wrong with your server, because I have multiple applications on lighthttpd, and no problems with POST.
#3

[eluser]christoz[/eluser]
What would be the right question for the host to answer, i need to give something to take notice. Using light http headers addon, i found that lighthttpd responses with 301 header while apache with 302
#4

[eluser]skunkbad[/eluser]
Why don't you show us the simplest cose example that fails, so we can make sure it is not your code.
#5

[eluser]christoz[/eluser]
CI version 2.1.2
lighthttpd version
Code:
["SERVER_SOFTWARE"]=> string(15) "lighttpd/1.4.31"


This is the form tag generated by calling and echoing
Code:
form_open('admin/actions/insert/'.$cur_seg, $form_attributes);

Code:
<form action="http://.../.../index.php/admin/actions/insert/0" method="post" accept-charset="utf-8" class="stdform stdform2" id="form2">        ....
</form>

Some input fields inside form
Code:
<p>
  <label for="slug">Slug</label>
  <span class="field">
    &lt;input type="text" name="slug" value="" id="slug"   class="smallinput"/&gt;          

  &lt;input type="hidden" name="parent_id" value="0" id="parent_id" class=""  /&gt;
  </span>
</p>
<p>
// more input tags generated via CI input helper
</p>

This is the target controller method
Code:
public function insert($parent_id){
  //die(print_r($_POST));                                   Nothing in here
  var_dump($_SERVER);
  $img_array = $this->input->post('img_array');
  if(!empty($img_array)){
   $imgs_str = implode(',', $img_array);
  }else{

   $imgs_str = NULL;
  }

  $key_array = $this->input->post('keys_array');
  if(!empty($key_array)){
   $keys_str = implode(',', $key_array);
  }else{
  
   $keys_str = NULL;
  }

  $is_webdev = $this->input->post('is_webdev');
  $is_branding = $this->input->post('is_branding');
  $is_logotypo = $this->input->post('is_logotypo');
  $is_webdesign = $this->input->post('is_webdesign');

  if($is_webdev == '1') $project_type .= 'web-dev ';
  if($is_branding == '1') $project_type .= 'branding ';
  if($is_logotypo == '1') $project_type .= 'logotype ';
  if($is_webdesign == '1') $project_type .= 'web-design ';

  if(isset($project_type) == FALSE){
   $project_type = '';
  }
  
  $data_form_array = array(
   'parent_id' => $this->input->post('parent_id'),
   'slug' => $this->input->post('slug'),
   'title' => $this->input->post('title'),
   'intro' => $this->input->post('intro'),
   'body' => $this->input->post('body'),
   'date' => $this->input->post('date'),
   'url' => $this->input->post('url'),
   'is_webdev' => $this->input->post('is_webdev'),
   'is_branding' => $this->input->post('is_branding'),
   'is_logotypo' => $this->input->post('is_logotypo'),
   'is_webdesign' => $this->input->post('is_webdesign'),
   'project_type' =>$project_type,
   'has_child' => $this->input->post('has_child'),
   'num_childs' => $this->input->post('num_childs'),
   'img_id' => $this->input->post('img_id'),
   'zindex' => $this->input->post('zindex'),
   'meta_title' => $this->input->post('meta_title'),
   'meta_description' => $this->input->post('meta_description'),
   'selected_images' => $imgs_str,
   'selected_keys' => $keys_str
   );

  $toret ='';


  $query = $this->cms_model->add_page($data_form_array);

  if($query == TRUE){

   $this->session->set_flashdata('insertion_status', 'OK');
   redirect('admin/pages/'.$data_form_array['parent_id']);

  }else{

   $this->session->set_flashdata('insertion_status', 'FAIL');
   redirect('admin/pages/'.$data_form_array['parent_id']);
  }
}

Submiting a form outside CI deployment has no problems

http://www.christoz.gr/test.php

Forget about the GET, the point i think is that I don't get at least 302 Header Response with an alternative url to get redirected

#6

[eluser]skunkbad[/eluser]
What happens when you run this test controller:

Code:
&lt;?php

class Test extends CI_Controller {

public function index()
{
  $this->load->helper('form');
  
  echo '<pre>';

  var_dump( $this->input->post() );
  
  echo '</pre><hr />';

  echo form_open();

  echo form_input('name');
  
  echo form_submit('submit_button','Submit');
  
  echo form_close();
}

}
#7

[eluser]christoz[/eluser]
vardumb outputs
Code:
bool(false)

print_r($_POST) outputs
Code:
Array
(
)

header response
Code:
http://somedomain.gr/pinecone/index.php/test

POST /somedomain.gr/index.php/test HTTP/1.1
Host: somedomain.gr
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0 FirePHP/0.7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://www.somedomain.gr/pinecone/index.php/test
x-insight: activate
Content-Type: application/x-www-form-urlencoded
Content-Length: 31
name=hello&submit_button=Submit
HTTP/1.1 301 Moved Permanently
Location: http://www.somedomain.gr/pinecone/index.php/test
Content-Length: 0
Date: Mon, 19 Nov 2012 17:10:22 GMT
Server: lighttpd/1.4.31
----------------------------------------------------------
#8

[eluser]skunkbad[/eluser]
I'm curious about the 301 status in the header. Any idea why that is there? Perhaps that is the problem. Everything else in the header looks normal to me.
#9

[eluser]christoz[/eluser]
w3.org explains that http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Quote:10.3.2 301 Moved Permanently

The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.

The new permanent URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

Note: When automatically redirecting a POST request after
receiving a 301 status code, some existing HTTP/1.0 user agents
will erroneously change it into a GET request.

There is a notice that says
Quote: Note: When automatically redirecting a POST request after
receiving a 301 status code, some existing HTTP/1.0 user agents
will erroneously change it into a GET request.
Well that's me i guess
#10

[eluser]skunkbad[/eluser]
I know what a 301 is, but why are you redirecting the post? You should do all of your processing before the redirect.




Theme © iAndrew 2016 - Forum software by © MyBB