Jump to content

How can you inherit POST variables?


jmrozi1

Recommended Posts

Take the following code:

 

//index.shtml

<html>

<body>

  <!--#if expr=”$QUERY_STRING = /main=action/” -->

      <!--#include virtual=”action.php” -->

  <!--#else -->

      <!--#include virtual=”form.html” -->

  <!--#endif -->

</body>

</html>

 

//form.html

<form action=”index.shtml?main=action” method=”post”>

Enter name: <input name=”username” />

<br />Submit <input type=”submit” />

</form>

 

//action.php

<?php

if(array_key_exists(“username”, $_POST){

echo “Name entered: “ . $_POST[“username”] . “<br />”;

}

else{

echo count($_POST);

}

?>

 

My goal is to get the action page to output the “username” input upon submit, but the actual output will be “0”.  If I didn't need to use SSI, the most obvious solution would be to make the form pass directly to the action.php page or to use php rather than SSI for the index page.  However, I'd like to use SSI to include a standard header and footer that display Apache environment variables, so I'm looking for a way for index.shtml to pass form variables to an included php page, or at least to know whether or not it's possible.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/155033-how-can-you-inherit-post-variables/
Share on other sites

In this case, the code will always print "Hey! You're nameless!", regardless of the name entered.  This is because the form variables, which are being passed to the page "index.shtml?main=action", aren't being inherited by the included file "action.php".

 

I've been looking further into the problem and found that environment variables are inherited.  For example, if I create an apache variable in index.shtml: <!--#set var="testVariable" value="test" -->, then I'll be able to recall this variable in "action.php" as $_SERVER["testVariable"].  This can be used to pass GET variables: <!--#set var="getVariables" value="$QUERY_STRING" -->, which could then be used in "action.php" as $_SERVER["getVariables"].  However, I'm not sure how to apply this approach to the POST method for passing variables.

Can you not write the includes in PHP then just use include() to call them in?

 

If you can stick to one way of doing things it makes it so much easier!

 

For this to work, I'd have to rename the file "index.shtml" to "index.php", which would mean that the SSI directives wouldn't work (I could configure the server to parse .php files for SSI, but this is generally bad practice).  I'll probably end up having to do it this way, but I was hoping to avoid it considering the amount of code I'd have to rewrite.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.