Welcome Guest, Not a member yet? Register   Sign In
$_POST issue - has to be my conf, right?
#1

[eluser]mplsCorwin[/eluser]
I have a linux dev server and I’m trying to setup a sandbox environment under windows 7. Things were going along swimmingly until I run into an issue where I can’t seem to find $_POST data from my CI_Controller sub-classes.

I’m assuming there’s got to be some sort of configuration issue here but neither Google nor IRC have yielded a solution. Here are some minimized examples illustrating my problem.

This (PHP only) works under both linux and windows:

Code:
<HTML>
<HEAD><TITLE>Hello, world!</TITLE></HEAD>
<BODY>
<FORM method="post" action="/hello3.php">
<input type="text" name="test" id="test" />
<input type="submit" />
</FORM>
   <br/><pre>&lt;?php print_r( $_POST ); ?&gt;</pre>
&lt;/BODY&gt;&lt;/HTML>

This works under linux but on my local the dump of $_POST always shows as Array( )
Code:
&lt;?php
class Hello3 extends CI_Controller {

public function index()
{
   //echo 'Hello World!';
  echo '&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE>Hello, world!&lt;/TITLE&gt;&lt;/HEAD>
&lt;BODY&gt;
&lt;FORM method="post" action="/hello3/"&gt;
&lt;input type="text" name="test" id="test" /&gt;
&lt;input type="submit" /&gt;
&lt;/FORM&gt;&lt;br/><pre>';

  print_r( $_POST );
  echo '</pre>&lt;/BODY&gt;&lt;/HTML>';
}
}
?&gt;

Thanks in advance for the kind and gentle way in which you have chosen to show me what a fool I am.
#2

[eluser]skunkbad[/eluser]
Try current_url() for the form action and see if that makes a difference.
#3

[eluser]mplsCorwin[/eluser]
Give me an error that current_url() is undefined. Also, not sure quite why that would yield a different result under linux/apache vs win7/apache ('tho I'm willing to be educated Wink
#4

[eluser]skunkbad[/eluser]
[quote author="mplsCorwin" date="1340499914"]Give me an error that current_url() is undefined. Also, not sure quite why that would yield a different result under linux/apache vs win7/apache ('tho I'm willing to be educated Wink[/quote]

You have to load the url helper. I just thought you might not be posting back to the same controller, but if you for sure are, then I don't know. Do you get the same result when you use $this->input->post() ?
#5

[eluser]mplsCorwin[/eluser]
Thank you, and sorry if I was short in my previous. Trying to punch out a reply before my toddler exploded.

Short answer, yes same result.

Long answer, submitting to this updated version of the source:
Code:
&lt;?php
class Hello3 extends CI_Controller {

public function index()
{
  
   $this->load->helper('url');
   //echo 'Hello World!';
   $url = current_url();
  echo '&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE>Hello, world!&lt;/TITLE&gt;&lt;/HEAD>
&lt;BODY&gt;
&lt;FORM method="post" action="'.$url.'"&gt;
&lt;input type="text" name="test" id="test" /&gt;
&lt;input type="submit" /&gt;
&lt;/FORM&gt;&lt;br/>$_POST:<pre>';

  print_r( $_POST );
  echo "</pre><br />Input-&gt;Post:<pre>";
  print_r( $this->input->post() );
  echo '</pre>&lt;/BODY&gt;&lt;/HTML>';
}
}
?&gt;

Yields this result on the windows box:
Code:
&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE>Hello, world!&lt;/TITLE&gt;&lt;/HEAD>
&lt;BODY&gt;
&lt;FORM method="post" action="http://127.0.0.1:8080/hello3"&gt;
&lt;input type="text" name="test" id="test" /&gt;
&lt;input type="submit" /&gt;
&lt;/FORM&gt;&lt;br/>$_POST:<pre>Array
(
)
</pre><br />Input-&gt;Post:<pre></pre>&lt;/BODY&gt;&lt;/HTML>

And this one under linux:
Code:
&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE>Hello, world!&lt;/TITLE&gt;&lt;/HEAD>
&lt;BODY&gt;
&lt;FORM method="post" action="http://otterology.bru.st/hello3"&gt;
&lt;input type="text" name="test" id="test" /&gt;
&lt;input type="submit" /&gt;
&lt;/FORM&gt;&lt;br/>$_POST:<pre>Array
(
    [test] => asdf
)
</pre><br />Input-&gt;Post:<pre>Array
(
    [test] => asdf
)
</pre>&lt;/BODY&gt;&lt;/HTML>
#6

[eluser]skunkbad[/eluser]
Well that's just not normal!

If you haven't already done so, I'd try replacing the system directory with a fresh copy. I've had a corrupt download of CI run my around in circles for hours, and that's what fixed it for me. Unfortunately, that's all I've got for you.
#7

[eluser]mplsCorwin[/eluser]
Many thanks for the replies. Integrating the latest stable of CI is exactly what I'm working on right now. I shall post an update when finished.

EDIT: Done. Update from 2.0.2 to 2.1.1 didn't appear to change things. Test cases produce the same results.
#8

[eluser]mplsCorwin[/eluser]
Rewrite rule. Worked fine when I run it as http://me/index.php/hello3/

I'll post some specifics of what the Win7x64/Apache 2.2.22 combination didn't like about my .htaccess file (but which Apache under linux thought was just fine) when I get that far.

[EDIT] Solved. Works great once mod_rewrite is loaded.
#9

[eluser]InsiteFX[/eluser]
If you want to use localhost instead of 127.0.0.1 edit this file.
Code:
c:\Windows\System32\drivers\etc\hosts

// Add this
127.0.0.1 localhost

You can right click on the file and use notepad to edit it.
#10

[eluser]wiredesignz[/eluser]
[quote author="InsiteFX" date="1340520513"]If you want to use localhost instead of 127.0.0.1 edit this file.
Code:
c:\Windows\System32\drivers\etc\host
[/quote]
@InsiteFX, the filename is "hosts" not host and it already has the localhost entry by default.

In any case that has absolutely nothing to do with the problem.

It seems that you and your friends just keep taking the level of intelligent discussion in these forums to new lows.

FYI, the OP has already resolved his problem. It wasn't a PHP or CI bug. He simply forgot to enable mod_rewrite.




Theme © iAndrew 2016 - Forum software by © MyBB