title: How to protect $_POST and params from hackers
body: <p>I'm using this with <a href="https://github.com/niklasvh/html2canvas" rel="nofollow">html2canvas.js</a> to generate and save images from HTML.</p>
  
  <p>I use url params to make this work - eg: <code>website.com/?price=10&amp;name=xxx</code></p>
  
  <p>All ok untill here - the script works fine - images are saved in <code>/cart/</code> dir </p>
  
  <pre><code>&lt;?php
  $image = $_POST['image'];
  $username = $_POST['username'];
  $front_class = $_POST['front_plass'];
  $decoded = base64_decode(str_replace('data:image/png;base64,', '', $image));
  $date = date('d-M-Y-h-i-a', time());
  $curdir = getcwd();
  $cartDir = $curdir ."/cart";
  $userDir = $cartDir.'/'.$username;
  if (!file_exists($userDir)) {
      mkdir($cartDir.'/'.$username, 0777);
  }
  $name = $front_class."-front-".$date.".png";
  $full_path = $userDir.'/'.$name;
  $name1 = 'cart/'.$username.'/'.$name;
  function ImageFillAlpha($image, $color) {
      imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $color);
  }
  function imageCreateCorners($sourceImageFile, $name, $radius) {
  ...
  }
  file_put_contents($full_path, $decoded);
  imageCreateCorners($full_path, $name, 25);
  echo '&lt;img src="'.$name1.'" alt="front" id="front_img" /&gt;'; 
  ?&gt;
  </code></pre>
  
  <p>And the js</p>
  
  <pre><code> html2canvas($('#front'), {
          "logging": true,
          //"proxy":"html2canvasproxy.php",
          "onrendered": function(canvas){
                 var dataURL = canvas.toDataURL("image/png");
                 $.post('image_front.php',{
                      image: dataURL,
                      username: username,
                      front_class: frontClass
                 },function(data){
                      $('.imageHolder_front').html(data);
                 });
          }
  });
  </code></pre>
  
  <p>The problem is that someone hacked me twice yesterday thought this and I need to protect the <code>$_POST</code> or the params can be the problem?</p>
  
  <p>Any help here please? I'm not really good with backend development - more with frontend.</p>
  
  <p>Thanks.</p>