LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2006, 05:41 PM   #1
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
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?
 
Old 04-03-2006, 11:12 AM   #2
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
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.
 
Old 04-04-2006, 09:11 AM   #3
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Original Poster
Rep: Reputation: 116Reputation: 116
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP if(isset($_POST[\'submit\'])) wont evaluate true ALInux Programming 1 11-07-2005 04:22 AM
Large file upload - $_POST empty in PHP PsychosisNode Linux - Software 1 01-23-2005 07:32 AM
Changing a table contents dynamically based on select box rose_bud4201 Programming 4 01-13-2005 10:48 AM
PHP : $_POST['choice$i'] doesnt work WindowsBurner Programming 7 12-18-2004 08:06 AM
index.php to list the contents of the dir?? bruno buys Linux - Software 1 08-30-2004 02:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration