LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   changing contents of $_POST in PHP (https://www.linuxquestions.org/questions/programming-9/changing-contents-of-%24_post-in-php-431096/)

jiml8 04-02-2006 05:41 PM

changing contents of $_POST in PHP
 
A few days ago I asked on this board if anyone knew Joomla and could tell me how to hook the mosdirectory plugin.

Well, I figured it out.

Now, I needed to hook it because I needed to do some processing of a user input prior to letting mosdirectory have it.

Basically, the user pays for a subscription that lets him enter information in one category of a directory. But mosdirectory has no facility to lock him into one category, so even if he only paid for one category he could enter information into multiple categories.

So my task was to intercept the Save submission, make sure that he had only entered data into one category, and if he had entered into multiple categories I had to fix it.

Now, I have decided that the easiest way to fix this is to just keep the first category he defined and strip all others. So I have done so as follows:

Code:

      $cidnum = mosGetParam($_POST,'cid','');
      $countval = count($cidnum);
      if ($countval > 1) {
        $slen = readfile("php://input");
        $fn2 = fopen("php://input","r");
        $post = fread($fn2,$slen);
        fclose($fn2);
        $hdrstr = "cid%5B%5D=";
        $nn = 1;
        $tststr = "";
        while ($nn <= $countval-1) {
          $tststr .= $hdrstr.$value[$nn]."&";
          $nn=$nn+1;
        }
        $post=str_replace($tststr,"",$post);
        $fn2 = fopen("php://input","w");
        fwrite($fn2,$post);
        fclose($fn2);
      }

Now, the mosGetParam is a function that in this case will return to me all the category IDs that the user has entered. There should only be one.

If there is more than one, I construct the string that will strip the extras out, and apply it, leaving me with a properly corrected $_POST string in $post.

I then try to write this corrected string out to the input stream, and I cannot. The function appears to work, but doesn't.

My alternative is to construct a new POST and submit it. While I can do this if I have to, it will complicate some of my logic downstream. Can I re-write the POST, or do I have to resubmit it?

lackluster 04-03-2006 11:12 AM

I've never seen that php://input thing before. Seems like something useful for CLI, but in a page, you should be able to just $_POST['value'] = 'whatever'; since it's just a simple array.

jiml8 04-04-2006 09:11 AM

You would think so, but this doesn't seem to be changing anything.

I have tried setting $_POST['cid'] = $myval; and nothing changes.

Since in the multi-category case cid is an array I have done an unset($_POST['cid']); then tried setting it, again with no result.

It seems that I cannot change the $_POST no matter what I do. This is puzzling.


All times are GMT -5. The time now is 03:04 AM.