Can't get $_POST to work

software development

#1

here’s the url

http://rlr.wadescape.com/test02.php?test=justin

here’s the code:

<?php echo $_POST['test']; ?>

it comes up blank, now why, I can’t figure it out…


#2

Got it

<?php echo $HTTP_GET_VARS['test']; ?>

That’s what you get for hacking at PHP, and zero experience.


#3

[quote]That’s what you get for hacking at PHP, and zero experience.

[/quote]

In case you found the answer but aren’t 100% sure why it works now, you were trying to pull a value from a “POST” submission, while name/value pairs appended to the end of a URL are actually submitted using “GET”.

In your case, you should probably use $_GET[‘blah’] instead, as that’s what the PHP folks are recommending. $HTTP_GET_VARS[‘blah’] won’t be going anywhere any time soon I imagine, though.

POST is more common with actual form submissions, though both POST and GET will work depending on what method you specify as an attribute to your form tag. The main (and only, really) benefit with POST is that it doesn’t clutter up the location bar, and handles large input submissions - such as files.

If you want to pull input from any method and don’t care to specify what kind directly, you can simply use $_REQUEST[‘blah’]. In theory splitting these sorts of submissions was done for security, but that’s a bit of a red herring in my opinion. It’s rather simple to forge a request of any type (except possibly $_SESSION[‘blah’]), and you should do input checking for any non-trivial script … Particularly one that interacts with the file system or a database.

  • Jeff @ DreamHost
  • DH Discussion Forum Admin