1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem with Method=Post

Discussion in 'PHP' started by paulocon, May 8, 2009.

  1. #1
    Hi all,

    Recently developed a website on my own hosting server and all worked fine. Ported it across to the clients server and for some reason, my forms don't work.

    e.g.

    login.php...

    <form name="form1" action="" method="post" >
    <input type="text" name="username" size=18>
    <input type="password" name="password" size=18>
    <input type="submit" name="Submit" value="Log In">
    </form>

    If I now

    echo $username;

    I get nothing (i.e. $username is blank)..

    If I do the following:

    echo $_POST['username'];

    I get the value input into the form.

    This same code works fine on two hosting servers I have tried.

    Anyone know any reason for this behaviour and how I can fix it?

    Any help would be very much appreciated..
     
    paulocon, May 8, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Probably for security reasons Register Globals is turned off (the feature that automatically converts posts, gets etc into variable.

    So naturally with it off you need to check to see if $_POST['username'] exists, then copy it into $username. Its off because in some cases it can be a bad way to exploit a login ( post vs get etc)

    Most shared hosting have things like register globals, safe mode, etc turned off, so need to take that into consideration when developing scripts for distribution.
     
    kblessinggr, May 8, 2009 IP
  3. usadesi

    usadesi Peon

    Messages:
    296
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you have to go throught the bin folder .
    There you can find the Register Globals off.Inplace of OFF you write ON .
    Then it will work........
     
    usadesi, May 8, 2009 IP
  4. mrmaf

    mrmaf Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah kblessinggr and babu99 is quite right. Follow the steps that they mentioned. But i suggest to use $_POST[] and $_GET[] depends upon the form method you are using because after reading these two words anyone can understand that data is coming from FORM, so if any new developer wants to continue the code that once you have written then it will be quite simple for him/her to understand the whole logic.

    It's just suggestion :)
     
    mrmaf, May 8, 2009 IP
  5. paulocon

    paulocon Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Cheers all for the help.

    It was indeed register globals. Any reason why I shouldn't be using this methodology?
     
    paulocon, May 11, 2009 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Register Globals should be set to "off" - simply because register globals is a major security hole, and there are no reasons why you should use it for anything. Just use the proper coding practices: $_POST[] and $_GET[], and always sanitize user-input, so as to avoid injection attacks.

    Personally I would not even use GET for anything remotely important - just for temp variables for browsing and simliar use - POST usually wins hands down for "security" (although both can be exploited if not done correctly).

    It's bascially bad practice to rely on things like register globals being turned on, as it will be deprecated in future releases of PHP, and as stated above, is a security risk.
     
    PoPSiCLe, May 13, 2009 IP