Welcome to WebmasterWorld Guest from 50.17.117.221

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

A silly $_POST question

Can you include variables in the brackets?

     
7:07 pm on Nov 9, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 3, 2004
posts:445
votes: 0


What I am trying to do is dynamically load a form for updating a text file. In dynamically building my form, I have line number and field number to name the fields. ie.

echo "<input type='text' name='$linecount_$filedcount' value='whatever'>";

When I send this to the next page ... I would like to write to the file like this:

$tempvar = $linecount . "_" . $fieldcount";
fwrite($fh, $_POST[$tempvar]);

Of course I don't even know if a variable in the $_POST array is even possible. Is it?

7:39 pm on Nov 9, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 26, 2004
posts:155
votes: 0


It's fine -- $_POST is just a (superglobal) array.
9:46 pm on Nov 9, 2005 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


you could also just run through the $_POST array with a foreach as well, getting the keys at that point, allowing less margin for error. Making sure you build the exact same thing twice can sometimes get a little out of control.

Also before you just start writing vars into files I would clean them first. The general scenario is a perfect one for XSS.