Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3759240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:17:09+00:00 2026-05-19T10:17:09+00:00

If you have an item where you allow users to add comments, how can

  • 0

If you have an item where you allow users to add comments, how can you pass which item the user is replying too?

I’ve though of using a hidden field in a form, however this can be easily changed using plugins such as firebug:

<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>

Or just simply using a session:

$_SESSION['item_id'] = $item_id

Is there a safe way to send the item data in a form?

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.

I though of doing something like

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

then in the form have a hidden field:

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

Finally check the session matches the id clicked:

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');
}

However after reading some of your comments I guess this is a bad idea?

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.

Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:17:10+00:00Added an answer on May 19, 2026 at 10:17 am

    Using a session the way you suggested would screw up cases where (1) a visitor opens several different articles in multiple tabs, and (2) tries to write a reply on any tab other than the one that was opened last. The user might even write two replies simultaneously in different tabs; I sometimes do that on StackOverflow. Web developers so easily forget that today’s visitors may have several browser tabs open at the same time. Really, we don’t use IE6 anymore.

    A solution would be to make $_SESSION['item_id'] an array of recently viewed article IDs, but then you won’t be able to stop some Firebug user (or any other tech savvy person) from replying to a previously viewed article. Adding time limits won’t change anything, either.

    But why would somebody intentionally change the ID of the post to which they’re replying, except to troll or spam the site? And if somebody really wanted to screw your site, they can easily get around any protection by making their bot request the appropriate page just before posting a spam comment. You’d be much better off investing in a better CSRF token generator, spam filter, rate limiter, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a ready made solution to allow users to add comments to an
I have a ListView that will allow the user to long-press an item to
I have a custom media item template that allows users to add category filters
I have a list view control which at the moment only allows one item
I have a treeview (winforms) which have different item types on it. I have
I have created an Item Template using the Export Template wizard. I opened up
I have a simple view function that's designed to allow the user to choose
I've created Outlook 2007 macro, which add additional item to mail context menu (
I have recently created an Android application that allows users to add shopping items
I'm creating a UX experience that will allow the user to add items to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.