Form POST veya oturumlar?

0 Cevap php

Eğer kullanıcılar yorum eklemek için izin veren bir öğeyi nasıl kullanıcı da cevap verirken hangi madde geçebilir varsa?

Ben bir formda bir gizli alan kullanmak olsa da, ancak bu kolay gibi kundakçı gibi eklentileri kullanarak değiştirilebilir ettik:

<form method="post" action="blah">
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">
<!-- other form data here -->
<input type="submit" name="submit">
</form>

Ya da sadece basit bir oturum kullanarak:

$_SESSION['item_id'] = $item_id

Bir formda madde veri göndermek için güvenli bir şekilde var mı?

Edit: This is after validation,... I do implement some XSS protection (form tokens etc). The reason I was asking was just to know what the best practise is.

Ama böyle bir şey yapıyor

$_SESSION['item_id'] = $id //this is set when they visit the current item

daha sonra şeklinde bir gizli alan var:

<input type="hidden" name="item_id" value="<?php echo $id?>">

Sonunda oturumu kontrol id tıklandığında eşleşir:

if ($_SESSION('item_id') !== $item_id) //the value posted in the form
{
   die('There\'s got to be a morning after
       If we can hold on through the night
       We have a chance to find the sunshine
       Let\'s keep on looking for the light');
}

Ancak sizin bazı yorumlar okuduktan sonra ben bu kötü bir fikir olduğunu tahmin?

(@ Gerçeküstü Düşler) Adil olmak gerekirse: Onlar id değiştirmek yaparsanız ben söylediğim gibi, ben sadece en iyi uygulama arıyordu, bu büyük bir anlaşma değil.

Şerefe.

0 Cevap