Changing a form's action field

Hi everyone
I was wondering if there is a way to change a form’s action field everytime a new user loads the page, e.g if form action=“dir/path1/myfile.php” for the first user that loads the page, and form action=“dir/path2/myfile.php” for the second user, and form action=“dir/path3/myfile.php” for the third user and so on. Then after its gone through say 10 different paths it loops back to the first path again. Any help as always, is greatly appreciated. Cheers

The easiest way would be just get the number from a file, increment the number, and save it.

Here is an example:

<?
   $num = file_get_contents("file_num.txt");
   if(!$num) $num = 1;
   echo '
<form method="post" action="dir/path'.$num.'/myfile.php">
<input type="submit" value="Send" name="submit" />
</form>';
   if(++$num>10) $num = 1;
   $fp = fopen("file_num.txt","w");
   fwrite($fp,$num);
   fclose($fp);
?>

If you wish the user return to the same form then you have to save the $num for that user.

Here is an updated example:

<?
   session_start();
   if($_SESSION['file_num']) $num = $_SESSION['file_num'];
   else
   {
	   $num = file_get_contents("file_num.txt");
	   if(++$num>10) $num = 1;
	   $fp = fopen("file_num.txt","w");
	   fwrite($fp,$num);
	   fclose($fp);
	   $_SESSION['file_num'] = $num;
   }
   echo '
<form method="post" action="dir/path'.$num.'/myfile.php">
<input type="submit" value="Send" name="submit" />
</form>';
?>

Thanx for the reply tom8 but I’m failing to understand this, are you saying I need to create a file named “file_num.txt” and if so, what exactly am I writing in this file. Sorry I’m just a dumb ass aussie trying to teach myself web design. Cheers

No the user will not be returning to the same form even if they click on refresh a new path will be used, every user will have their own path to “myfile.php”. Cheers

Hey tom8 your a legend dude!! Once I played with this a little bit and got a grasp on what it was trying to do, and a couple of 404 errors later, everything worked perfectly. Thank you very, very much, you just saved me from another packet of headache tablets. Cheers

Sorry I could not answer your question since I was sleeping while you were figuring out how my solution would work. I’m glad you got it working. As you can see, you no dumb a**… :smiley:

We’re often encountering obstacles from time to time. But with perseverance we will overcome them as you did.

The solution I suggested was based on changing a single number to the path. But if you need a complete different name for each path then you need something like this:

<?
   $num = file_get_contents("file_num.txt");
   if(++$num>9) $num = 0;
   $fp = fopen("file_num.txt","w");
   fwrite($fp,$num);
   fclose($fp);

   $action = array(
		    "dira/path01/myfileq.php",
		    "dirb/path02/myfiler.php",
		    "dirc/path03/myfiles.php",
		    "dird/path04/myfilet.php",
		    "dire/path05/myfileu.php",
		    "dirf/path06/myfilev.php",
		    "dirg/path07/myfilew.php",
		    "dirh/path08/myfilex.php",
		    "diri/path09/myfiley.php",
		    "dirj/path10/myfilez.php");

   echo '
<form method="post" action="'.$action[$num].'">
<input type="submit" value="Send" name="submit" />
</form>';
?>

(or just use sessions and use the session identifier as the path…)

Thanx guys, I’ll keep all this for reference, now that I’ve got this sorted out, I got a lot of work to catch up on and will, no doubt, will have many more dumb ass questions to ask along the way. You guys and this site rock!!!