How to use cookies in Drupal? I am writing a module that allows users to put comment on each paragraph.
So in my module I have added a new field to comment table called "paragraph_id" and I have also added a new field to comment form that say:

 Which paragraph do you want to put comment on?


After each paragraph I have added a link saying:

  Put comment on paragraph 1 (2,3, ...., the number changed based on the number of the paragraph.


in order to this, I have written the following in node.tpl.php:

        for ($i=1;$i&lt;$number;$i++) {

        print render($paragraphs[$i]);
       ?&gt;

      &lt;a href="#commenting"&gt;Put comment for Paragraph &lt;?php echo $i?&gt;&lt;br&gt;&lt;/a&gt;


    &lt;?php


I want to do one the following options:

1) Eliminate the new field which asks for the number of the paragraph from comment form, and do something that when a user for example clicks on a link like:

   Put comment on paragraph 1


, the number "1" automatically got save in comment table in "paragraph_id" field.

2) Or  keep the field that asks for paragraph number in comment form and when user clicks on a link like 

 Put Comment on Paragraph 1


while he is getting directed to the comment form, the value of that field (paragraph_number in comment form) sets to 1.

How can I do it?
Drupal automatically ensures that a user has a session, so your script can simply read and write to the $_SESSION superglobal array.