PHP is unable to retrieve information via $_POST on my localhost but $_GET works?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tpaine
    New Member
    • Nov 2006
    • 9

    PHP is unable to retrieve information via $_POST on my localhost but $_GET works?

    Let me preface this by saying that this is most certainly not a code issue but a config issue. I have been able to implement the code fine on my live server, this problem only occurs on my localhost. I have 7 years experience with various web langauges so we can skip the "METHOD='PO ST'" comments.

    I recently setup PHP and Apache (and mySQL) on my windows XP box. This is my first experience with PHP and it took me a long time to get everything working so bear with me. Everything was fine until I attempted to grab something using $_POST["mypostvar"] which returned an error saying "mypostvar" was not found while $_GET["mygetvar"] works fine.
    The exact error is : "Notice: Undefined index: mypostvar".
    I tried running var_dump($_POST );die; and it also returned nothing. I've tried all sorts of changes within php.ini including:
    register_global s = "on"
    gpc_order = "GPC"
    I also tried the following things:
    $_REQUEST["process"]
    $HTTP_RAW_POST_ DATA with always_populate _raw_post_data on

    I have scoured the internet looking for a solution and so far the only thing I found was a solution that I have to pay for over on Experts-Exchange . I would really not have to pay $10 for the answer but I find developing via FTP to be unacceptable.

    Version Info:
    PHP Version 5.2.0RC6-dev
    Apache Version:Apache/2.2.3 (Win32) PHP/5.2.0RC6-d
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I am sorry, but I don't have a clue. The only thing I could think of was the variables_order and the post_max_size parameters in php.ini.

    What is the effect of omitting E,C and S like you do? Not that I can think of a logical explanation, but just to be sure I'd try the default variables_order ='EGPCS'. You haven't accidentally set the post_max_size to 0, have you? No I don't think so. But still, give it a try.

    Sorry I can't help you here really, but I've tried.

    Ronald :cool:

    Comment

    • steven
      New Member
      • Sep 2006
      • 143

      #3
      It seems a little strange how you can find the GET variable, but not the POST. If the data is being sent via POST it should not show up in GET.

      On the page in question, can you place this code after the POST has been submitted. It should print an array of all the input.

      Code:
      echo "<pre>".print_r($_REQUEST, 1)."</pre>";

      Comment

      • tpaine
        New Member
        • Nov 2006
        • 9

        #4
        Originally posted by ronverdonk
        I am sorry, but I don't have a clue. The only thing I could think of was the variables_order and the post_max_size parameters in php.ini.

        What is the effect of omitting E,C and S like you do? Not that I can think of a logical explanation, but just to be sure I'd try the default variables_order ='EGPCS'. You haven't accidentally set the post_max_size to 0, have you? No I don't think so. But still, give it a try.

        Sorry I can't help you here really, but I've tried.

        Ronald :cool:
        Thanks for the tips Ronald but I'm still stuck :-\

        I have "post_max_s ize = 8M" by default and I tried variables_order = "EGPCS" with no success.

        I'm so ideologically opposed to paying for information like this but it's to the point where I've wasted far more money in time spent on this issue. I will have to resort to Experts-Exchange if I don't get any more tips in the next day. When I do find the answer I will be sure to post it back here.

        Comment

        • tpaine
          New Member
          • Nov 2006
          • 9

          #5
          Originally posted by steven
          It seems a little strange how you can find the GET variable, but not the POST. If the data is being sent via POST it should not show up in GET.

          On the page in question, can you place this code after the POST has been submitted. It should print an array of all the input.

          Code:
          echo "<pre>".print_r($_REQUEST, 1)."</pre>";
          My original post was a little confusing, but it's not that information that should be in the POST is showing up in the GET. What I meant to say is that information passed in the query string is retrievable while information passed in a post is not.

          Comment

          • seangates
            New Member
            • Dec 2006
            • 19

            #6
            Originally posted by tpaine
            URL=https://secure.experts-exchange.com/register.jsp?qu ery=php+_post+e mpty&clearTAFil ter=true&srid=z jn%2BshtK13RDZy ry87R6HA%3D%3D& redirectURL=%2F search.jsp%3Fqu ery%3Dphp%2B_po st%2Bempty%26se archType%3Dall% 26Submit.x%3D0% 26Submit.y%3D0& rsid=10]Experts-Exchange[/URL] . I would really not have to pay $10 for the answer but I find developing via FTP to be unacceptable
            An easy way around Experts-Exhange (at least existing answers) is when you have found the answer through Google to click on "Cached". It'll show the answers plain as day. :-)

            Sean

            Comment

            • tpaine
              New Member
              • Nov 2006
              • 9

              #7
              Originally posted by seangates
              An easy way around Experts-Exhange (at least existing answers) is when you have found the answer through Google to click on "Cached". It'll show the answers plain as day. :-)

              Sean
              Perhaps you have a better method than I but i believe EE places their "pay for" answers in spot blocked in their robots.txt so spiders (ie: search engines) can't find/cache it. This is what I get when I attempt to use Google Cache

              Comment

              • steven
                New Member
                • Sep 2006
                • 143

                #8
                Did you try printing the $_REQUEST array as I suggested? It should show everything passed in via cookies, post and get. See if anything shows up after your post send. It will at least determine if the data is even reaching php.

                Comment

                • tpaine
                  New Member
                  • Nov 2006
                  • 9

                  #9
                  Originally posted by steven
                  Did you try printing the $_REQUEST array as I suggested? It should show everything passed in via cookies, post and get. See if anything shows up after your post send. It will at least determine if the data is even reaching php.
                  oh sorry, yes I had already tried _REQUEST as well ... no luck

                  Comment

                  • seangates
                    New Member
                    • Dec 2006
                    • 19

                    #10
                    Originally posted by tpaine
                    Perhaps you have a better method than I but i believe EE places their "pay for" answers in spot blocked in their robots.txt so spiders (ie: search engines) can't find/cache it. This is what I get when I attempt to use Google Cache
                    Hmm. Works for me. Here's what I do:
                    1. Do a search on Google
                    2. Find an EE link
                    3. Click on "Cached" (down below) instead of the result link

                    Anyhow, do you have code we could look at? Not to insult your posts, but I haven't seen any code yet.

                    Thanks!
                    Sean

                    Comment

                    • tpaine
                      New Member
                      • Nov 2006
                      • 9

                      #11
                      Originally posted by seangates
                      Hmm. Works for me. Here's what I do:
                      1. Do a search on Google
                      2. Find an EE link
                      3. Click on "Cached" (down below) instead of the result link

                      Anyhow, do you have code we could look at? Not to insult your posts, but I haven't seen any code yet.

                      Thanks!
                      Sean
                      Yes some EE links are cached by google but not all. If you could find a cached version of the page I need I would be deeply in your debt.
                      As for my code it's incredibly simple:
                      Code:
                      <?
                      print "_REQUEST['process']:" . $_REQUEST['process'] . "<br>";
                      ?>
                      And the form looks like this:
                      Code:
                        <form action="ecard.php" name="frm" method="POST" onSubmit="return validateForm(this);">
                          <input type="hidden" name="process" value="free">
                          <input type="hidden" name="postcardHTML" value="">
                          Recipient's Email Address:<br><input type="text" size="40" name="emailTo"><br>
                          Sender's Email Address:<br><input type="text" size="40" name="emailFrom"><br>
                          Email Subject:<br><input type="text" size="40" name="subject"><br>
                          Message:<br><textarea name="message" rows="10" cols="40"></textarea><br>
                          <input type="button" value="preview" onClick="showPreview()">&nbsp;&nbsp;&nbsp;<input type="submit" value="send">
                        </form>
                      Last edited by pbmods; Apr 24 '09, 04:02 AM. Reason: Fixed CODE tags.

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        I am totally confused about this. I copied your code, made a JS function to do a validate and ran it (only thing I did not include was the preview routine). And without errors it shows up in the $_POST of the called script!

                        So I wonder, is there something in the JS validateForm that can cause this? I am no JS expert, but at least we could try to exclude all possible errors.

                        If you take the onsubmit validation call out of the form, does it work then?

                        Ronald :cool:

                        Comment

                        • steven
                          New Member
                          • Sep 2006
                          • 143

                          #13
                          Ok, I see you're trying to access request directly - don't bother. Try printing the entire REQUEST array just to see what it contains when you run your code.

                          I would try stripping down your form of all javascript calls, to see if they're the root of the problem. In fact, I just did it for you. I ran the form and I printed everything fine:

                          Code:
                          <form action="index.php" method="post" >
                              <input type="hidden" name="process" value="free" />
                              <input type="hidden" name="postcardHTML" value="" />
                              Recipient's Email Address:<br><input type="text" size="40" name="emailTo" /><br>
                              Sender's Email Address:<br><input type="text" size="40" name="emailFrom" /><br>
                              Email Subject:<br><input type="text" size="40" name="subject" /><br>
                              Message:<br><textarea name="message" rows="10" cols="40" ></textarea><br>
                              <input type="submit" value="send" />
                            </form>
                          Then ran this:

                          Code:
                          echo "<pre>".print_r($_REQUEST, 1)."</pre>";
                          And the output:

                          Code:
                          Array
                          (
                              [process] => free
                              [postcardHTML] => 
                              [emailTo] => asxas
                              [emailFrom] => xasxax
                              [subject] => asxasxas
                              [message] => xasxasx
                          )
                          Look at your javascript for debugging.

                          [edit]
                          Heh, I see I was beaten to the punchline. =]
                          Last edited by pbmods; Apr 24 '09, 04:02 AM. Reason: Fixed CODE tags.

                          Comment

                          • tpaine
                            New Member
                            • Nov 2006
                            • 9

                            #14
                            I tried running the same submit with zero javascript and with the generic _REQUEST with the same results. It does not surprise me that ronverdonk was able to run the code just fine because I do not think this is a code issue, rather it is a configuration issue with either apache or php.

                            Comment

                            • seangates
                              New Member
                              • Dec 2006
                              • 19

                              #15
                              Originally posted by tpaine
                              I tried running the same submit with zero javascript and with the generic _REQUEST with the same results. It does not surprise me that ronverdonk was able to run the code just fine because I do not think this is a code issue, rather it is a configuration issue with either apache or php.
                              And if you run it with $_POST? Using $_POST is more secure anyway, since it is a direct reference to the posted items and does not allow you to accept $_GET variables.

                              Sean
                              Last edited by seangates; Dec 5 '06, 11:36 PM. Reason: added comment about security

                              Comment

                              Working...