Note that there are some explanatory texts on larger screens.

plurals
  1. POForm POST or sessions?
    primarykey
    data
    text
    <p>If you have an item where you allow users to add comments, how can you pass which item the user is replying too?</p> <p>I've though of using a hidden field in a form, however this can be easily changed using plugins such as firebug:</p> <pre><code>&lt;form method="post" action="blah"&gt; &lt;input type="hidden" name="item_id" value="&lt;?php echo $item_id; ?&gt;"&gt; &lt;!-- other form data here --&gt; &lt;input type="submit" name="submit"&gt; &lt;/form&gt; </code></pre> <p>Or just simply using a session:</p> <pre><code>$_SESSION['item_id'] = $item_id </code></pre> <p>Is there a safe way to send the item data in a form?</p> <p><strong>Edit:</strong> This is <em>after</em> validation,... I do implement some XSS protection (form tokens etc). The reason I was asking was just to know what the best practise is.</p> <p>I though of doing something like </p> <pre><code>$_SESSION['item_id'] = $id //this is set when they visit the current item </code></pre> <p>then in the form have a hidden field:</p> <pre><code>&lt;input type="hidden" name="item_id" value="&lt;?php echo $id?&gt;"&gt; </code></pre> <p>Finally check the session matches the id clicked:</p> <pre><code>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'); } </code></pre> <p>However after reading some of your comments I guess this is a bad idea?</p> <p>To be fair (@Surreal Dreams): it isn't that big a deal if they do change the id, I as I've said,I was just looking for the best practice.</p> <p>Cheers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload