-1

I got an html/php page which you can select only 2 or below from the checkbox values. I limited the selection using javascript. But my concern is if someone tried to use developer tools they can simply disable my script and select more values from the checkbox. So I thought that I need to count how many POST data am I getting from the checkbox.

I tried using the count() in php to count the post and tried to echo the count and I get the right number. I then tried using an if statement that will echo if the selected is more than 2. It worked but when I use header('Location:') it skips it.

$countpres = count($_POST['pres']);
if($countpres>=3){
   header('Location:../index.php');
}
for($i=0;$i<$countpres;$i++)
{
$sql1 = "UPDATE candidate_list SET vote_count= vote_count + 1 WHERE candidate_number = '". $_POST['pres'][$i]. "' ";
mysqli_query($conn, $sql1);
}   

I need to go to index.php if ever the user tries to send more than 2 of the options.

Need Help
  • 51
  • 6

1 Answers1

1

For php7

header("location: index.php",  true,  301 );  exit;

For php5

header("Location: index.php");
exit();

If still it not work and faild to redirect thn use:

echo '<script>windows.location = "index.php";</script>'; exit();

Or

echo "<script type='text/javascript'>window.top.location='index.php';</script>"; exit();

Replace index.php with your file

Salman Khan
  • 158
  • 1
  • 7