php using post form to pass variables to itself?
Page 1 of 1
spankie
VIP Member



Posts: 2958
Location: Belgium
PostPosted: Sun, 5th Apr 2009 02:07    Post subject: php using post form to pass variables to itself?
hi,

i have a very weird problem... I have used this method like a zillion times before, but it looks like i am missing something...

I just want to pass variables via a form using POST to another php script. That php script verifies the data and passes it to itself and show a confirm button.

But for some reason the paramters that get passed to the script itself are not captured using $_POST[''], quite desperate atm...

what is wrong wizards?



Code:
<html>
<body>
<?php

   /* DB connect */
   $con = mysql_connect("localhost","tralallalala","tralalalalalalala");
     
   if (!$con){
      die('Could not connect: ' . mysql_error());
   }
     
   mysql_select_db("tralalalallaallala", $con);
   
   /* Read values */
   $pos[1] = $_POST["pos1"];
   $pos[2] = $_POST["pos2"];
   $pos[3] = $_POST["pos3"];
   $pos[4] = $_POST["pos4"];
   $pos[5] = $_POST["pos5"];
   $pos[6] = $_POST["pos6"];
   $pos[7] = $_POST["pos7"];
   $pos[8] = $_POST["pos8"];
           
   $pole   = $_POST["pole"];
   $fast   = $_POST["fast"];
       
   $race   = $_POST["race_name"];   
   $send   = $_POST["prono_send"];
   
   echo "Prono voor race #".$race."<br>\n\n";

   /* Pre confirming */
   if ($send == "Prono verzenden!"){
     
      /* Error checker */
      $errors = 0;
   
      /* Check zelfde drivers */
      for($i = 1; $i <= 8; $i++){
         for($j = $i+1; $j <= 8; $j++){
            if ($pos[$i] == $pos[$j]){
               echo "Positie met zelfde naam: positie ".$i." en positie ".$j."<br>\n";
            }
         }
      } 
     
      /* Check 0 */
      for($i = 1; $i <= 8; $i++){
         if ($pos[$i] == 0){
            echo "Positie ".$i." is niet ingevuld!<br>\n";
            $errors++;
         }
      } 
     
      if ($pole == 0){
         echo "Pole position is niet ingevuld!<br>\n>";
         $errors++;
      }
     
      if ($fast == 0){
            echo "Fastest lap is niet ingevuld!<br>\n>";
            $errors++;
      }
   
      /* Print 2 verify */
      if ($errors == 0){
     
         echo "<form action=\"prono_fill_submit.php\" method=\"post\">\n";
         echo "<table>\n";   
         /**/
         for ($i = 1; $i <= 8; $i++){
            echo "<tr><td>Positie".$i."</td><td>";
         
            $sql = "SELECT * FROM prono_drivers_09 WHERE nr = '$pos[$i]'";
            $result = mysql_query($sql,$con);
            $row = mysql_fetch_array($result, MYSQL_ASSOC);
            echo $row['nr']." ".$row['first_name']." ".$row['last_name'];
         
            echo "</td></tr>\n";
         }
       
         /**/
         echo "<tr><td>Pole Position</td><td>";
     
         $sql = "SELECT * FROM prono_drivers_09 WHERE nr = '$pole'";
         $result = mysql_query($sql,$con);
         $row = mysql_fetch_array($result, MYSQL_ASSOC);
         echo $row['nr']." ".$row['first_name']." ".$row['last_name'];

         echo "</td></tr>\n";
     
         /**/
         echo "<tr><td>Fastest Lap</td><td>";
       
         $sql = "SELECT * FROM prono_drivers_09 WHERE nr = '$fast'";
         $result = mysql_query($sql,$con);
         $row = mysql_fetch_array($result, MYSQL_ASSOC);
         echo $row['nr']." ".$row['first_name']." ".$row['last_name'];
     
         echo "</td></tr>\n";
         
         echo "<tr><td><input type=\"hidden\" name=\"pos1\" value\"".$pos[1]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos2\" value\"".$pos[2]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos3\" value\"".$pos[3]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos4\" value\"".$pos[4]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos5\" value\"".$pos[5]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos6\" value\"".$pos[6]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos7\" value\"".$pos[7]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pos8\" value\"".$pos[8]."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"pole\" value\"".$pole."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"fast\" value\"".$fast."\"></td><td></td></tr>\n";
         echo "<tr><td><input type=\"hidden\" name=\"race_name\" value\"".$race."\"></td><td></td></tr>\n";
               
         /* Confirm buttons etc */
          
    echo "<tr><td>Login</td><td><input type=\"text\" name=\"user\"></td></tr>\n";
         echo "<tr><td>Pass</td><td><input type=\"password\" name=\"pass\"></td></tr>\n";
         echo "<tr><td><input type=\"submit\" name=\"prono_send\" value=\"Prono definitief verzenden!\"></td><td><input type=\"reset\" value=\"User en pass wissen\"</td></tr>\n";
         echo "</table>\n";
         
         echo "</form>\n";   
         
         echo "<form action=\"prono_fill.php\" method=\"post\">\n";
         echo "<input type=\"submit\" value=\"ik zien biele, helemaal erbeginnen\">\n";
         echo "</form>\n";
      }
   }
   
   if ($send == "Prono definitief verzenden!"){
      $user = $_POST["user"];
      $pass = $_POST["pass"];
         
      $p1 = "race_".$race."_1";
      $p2 = "race_".$race."_2";
      $p3 = "race_".$race."_3";
      $p4 = "race_".$race."_4";
      $p5 = "race_".$race."_5";
      $p6 = "race_".$race."_6";
      $p7 = "race_".$race."_7";
      $p8 = "race_".$race."_8";
      $pp = "race_".$race."_p";
      $pf = "race_".$race."_f";
      $rd = "race_".$race."_date";
     
      $sql = "SELECT pass, $rd FROM prono_users_09 WHERE login = '$user'";
     
      echo $sql;
     
      $result = mysql_query($sql,$con);
      $row = mysql_fetch_array($result, MYSQL_ASSOC);
      if ($row['pass'] == $pass){
         if (!$row[$rd]){
            echo "Prono is bevestigd en zit in de DB @ pc tijd".time();
         }
         else {
            echo "Snoodaard! Je hebt al keer ingevuld @ ".$row[$rd];
         }
      }
      else {
         echo "pass mis, pipo, moest zijn: ".$row['pass']." en je vulde in: ".$pass;
      }
   }
   
   
   
   /* if prono_confirm_send  dan naar db en verify en zo  */
   
   /* Add login/pass verifier die terugkeert in de confirm dinges als de login bestaat en de pass mis is */

   
 
?>
</body>
</html>
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 5th Apr 2009 02:11    Post subject:
Sorry but is this your final code? No countermeasures against sql injections? I could be wrong as I am not a professionals @ php+sql but it seems as if somebody could add some bad bad mysql directives that could fuck up your db...

And hidden is NOT a good way to hide data from the user Laughing Why don't you write the sensitive data into a session variable?

And again, I'm not a pro Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sun, 5th Apr 2009 02:19    Post subject:
your hidden table contains value\"".$pos[2]
try replacing it with value=\"".$pos[2]
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 5th Apr 2009 02:21    Post subject:
loool right Very Happy


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sun, 5th Apr 2009 02:32    Post subject:
i never liked php because of stuff like this. php and html bugs are so fucking insidious. no compiler warning, no nothing. another reason is that working in php is paid worse than in other languages. but considering that i haven't managed to find another job in the almost 2 months that i've been unemployed, i'd love it right now Smile
Back to top
spankie
VIP Member



Posts: 2958
Location: Belgium
PostPosted: Sun, 5th Apr 2009 02:36    Post subject:
oh man, why isnt the debugger giving a warning then? that is like ahuge syntax error, i looked everywhere and did not notice it...

I am not hiding the data from the users, just want to pass some info to a next php thing without.


It is just a F1 game i am making for me and some friends. No time/skill to make it super injection proof, wont be public anyway... Very Happy
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 5th Apr 2009 03:07    Post subject:
Well than it's ok. Because they could easily chead by change the hidden confirmation data on the fly.


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sun, 5th Apr 2009 03:21    Post subject:
how would they go about doing that?
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 5th Apr 2009 12:28    Post subject:
wat?
 Spoiler:
 


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
lhzr




Posts: 3902
Location: RO
PostPosted: Sun, 5th Apr 2009 22:03    Post subject:
wat wat, in the wat?

i'm asking how could you change the post data on the fly Laughing
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 5th Apr 2009 22:26    Post subject:
While the confirmation page shows up, you could easily open up the sourcecoude via opera and change the values inside the hidden inputs Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group