![]() |
$_POST and $this->input->post() are always empty on localhost site - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: $_POST and $this->input->post() are always empty on localhost site (/showthread.php?tid=42793) |
$_POST and $this->input->post() are always empty on localhost site - El Forum - 06-19-2011 [eluser]ian[/eluser] I've been working with CodeIgniter for about a month to maintain and update a pre-existing website. I had never noticed this problem until needing to update a login page and noticed that none of my forms that perform a POST(this also includes a contact page that sends an email) were working on my development site running on my Macbook. I can access variables in $_POST outside of the CI install, but when placing them inside of a CI controller, trying to access the variables either through $_POST or $this->input->post('varname') gives me 0 values. I suspect the culprit is either in my config file or my .htaccess. I am using mod_rewrite and have some rewrite conditions/rules, mostly just allowing me to remove index.php from my URL. I've checked my header activity using the Live HTTP Headers Firefox extension, but do not see any redirects (and I don't expect any) that might cause the POST data to be lost. I'm accessing the site through a virtual host at http://url.dev that points to localhost. My environment: Mac OSX Apache 2.2 PHP 5.3.4 CodeIgniter 1.7.2 This has been driving me absolutely crazy for a week, and I don't understand how something as simple as accessing POST data can be so hard to do and so hard to track down in CodeIgniter. Any thoughts for things I could try? $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]Atharva[/eluser] Can you post your code $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]ian[/eluser] My View: Code: <h2><?php echo lang('user_login_header') ?></h2> My Controller Function: Code: public function login() My .htaccess Code: php_value upload_max_filesize 32M I'll be happy to post anything from my config.php file, but I don't want to post the whole thing if not necessary. I noticed I wasn't able to login to the page, so I initially thought it was a Session problem, but the first thing I tried was to print out the variables I was passing. Trying to print to the error log with Code: log_message('error', $this->input->post('email')); When I put Code: var_dump($user_data); object(stdClass)#36 (2) { ["email"]=> bool(false) ["password"]=> bool(false) } $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]InsiteFX[/eluser] Maybe if you move setting $user_data into the form_validation it just might work! InsiteFX $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]ian[/eluser] @InsiteFX Can you explain why you think that might fix the problem? Before it can run the validation, it needs those 2 values in the $user_data array. I should've mentioned that I don't think the logic of the code is the problem; it works on a remote production server, but isn't working for me on my local copy of the site. I also don't believe any of the validation code is in error. Validation is failing, but presumably because the POST value for email/password is empty/NULL (so, of course it's going to fail). $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]InsiteFX[/eluser] Because you are setting them before they have been inputed and validated! Until the form_validation has been run input values will be empty! InsiteFX $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]osci[/eluser] @ian Read this: form and $_POST problem on mac with MAMP. Maybe it helps you. @InsiteFX Why wouldn't I have an input->post before validation? If I didn't have validation I wouldn't have post variables from my form? $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]InsiteFX[/eluser] @osci, look at his code! $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]ian[/eluser] @InsiteFX, I'm still not sure how you recommend I change my code. Could you copy and paste the line(s) you think should change and show me where they should be? @osci, Thanks for the tip. It seems like those people were only having the problem when entering special characters. Unfortunately, that's not the case for me. I'm probably still going to downgrade my PHP to 5.2 to see if that helps and will report back with my findings. $_POST and $this->input->post() are always empty on localhost site - El Forum - 06-20-2011 [eluser]osci[/eluser] Quote:it works on a remote production server, but isn’t working for me on my local copy of the site.He said that his code works in production environment so I didn't look at the code actually. And didn't read your post carefully, because I was thinking of mac incompatibilities. Soz about that. @ian you said code works ?? You want $_post vars before you even submit the form? That's what code looks like. You don't call the form from another view/controller/method to submit right? It's just this login view. wrap your code in a Code: if ($this->input->post('btnLogin')) or do as InsiteFX said and test. |