Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[PHP] $_POST was empty due to syntax error

  • 01-09-2009 08:42AM
    #1
    Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭


    So last night I thought I'd install PHP5.2 on my WAMP server at home. Big mistake. 4 hours later I've wiped my server and reinstalled from WAMPServer2.0. Everything appears to be ok except my main login form wouldn't post or get data:
    <?php
    error_reporting(E_ALL);
    
    echo "<pre>";
    $data = file_get_contents('php://input');
    var_dump($data);
    print_r($_REQUEST);
    print_r($_POST);
    print_r( $GLOBALS );
    print_r( $HTTP_GET_VARS );
    print_r( $HTTP_POST_VARS );
    echo "</pre>";
    ?>
    
    When I ran this and posted the form I'd get:
    string(0) ""
    Array()
    Array()
    Array
    (
    [GLOBALS] => Array
    *RECURSION*
    [_POST] => Array
    (
    )

    [_GET] => Array
    (
    )

    [_COOKIE] => Array
    (
    [logged_in] => 1
    [PHPSESSID] => lrl9o34cc5p3u3fmd1dl502s51
    )

    [_FILES] => Array
    (
    )

    [_REQUEST] => Array
    (
    )

    [error] =>
    [lemail] =>
    [lpass] =>
    [lrem] => 0
    [data] =>
    )

    Notice: Undefined variable: HTTP_GET_VARS in C:\wamp\www\eazine\ver2\login.php on line 15

    Notice: Undefined variable: HTTP_POST_VARS in C:\wamp\www\eazine\ver2\login.php on line 16
    Reducing the form and checking all syntax, I found that the form itself was in a showform() function which took in 2 parameters, but on the initial call, I only had one, showform(""). Changing it to showform("", "") resolved the issue.

    Any reason why a) the form would still show and error_reporting wouldn't catch it? b) the resulting post would be empty? It had me googling for about a hour and a half before I figured it out.


Comments

  • Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭corblimey


    I tell a lie, I still have this problem. I was able to get in once, but not anymore. $_POST is constantly empty.


  • Registered Users, Registered Users 2 Posts: 6,655 ✭✭✭daymobrew


    Post the form html code.


  • Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭corblimey


    daymobrew wrote: »
    Post the form html code.

    After a few more attempts, I took the form html code out of the function I had it in, and it seems to be work fine now. Not sure why that works, but why it worked pre-PHP5.2 or WAMPServer2.0. If forms won't work in functions, I'm in a lot of trouble :p

    ETA: Ignore all my rambling above. It turned out that it was posting but on the next page I redirect back to login if a login cookie isn't set. However I was using HTTP_COOKIE_VARS instead of _COOKIE and this was always unset, so it would always redirect back to the login page with an empty _REQUEST. Simple.


Advertisement