I have a website with 3 pages, while each page has articles that are dynamically displayed from the database, and each has a specific article_id (int).. To make the comments for each article_id display very well, i decided to store the article_id in a $_SESSION while inserting comments into the db.
My problem now is that i’ll be having many more articles and $SESSION for each article/comments, will they not interfere with each other or mis function in the future?
Thanks
Problem To Which I Need The SESSION
although it does not answer your qestion, but here is how you should be dealing with.
since you need the
article_idwhile posting comment, and the article is being fetched from database. while fetching create an hidden input field likeand then while submitting the comment place this hidden field inside the comment form, and you will get the
article_id.Update:
here is how you should decide what to use and when.
a) when you need to send some variable with values from one page to another page with the purpose of maintaining the state between them. for example in one page you have displayed chunks of articles and when user clicks on
read more...you want to display them the full article with comments section. then you should probably use an anchor tag here. for example<a href="articledetail.php?id=2">Read More...</a>and inarticledetail.phppage you can use php’s$_GETto fetch the url in an array. in this case the value will be$_GET['id'] = 1b) use session only when you need something that should be accessible in your application as a whole not for maintaining the state like above(this case does not apply to AJAX based pages). for example you should use session to check if the user is logged in or not, or to store the user information like user id, username etc. since logically a user will be the one who will browse your application and you may sometimes need to access some information related to user in most of the pages. SESSION suits here.
c) hidden fields
<input type="hidden" name="article_id" value="<?php echo $_GET['id']; ?>"/>should be used when you want to send some hidden value for example via
$_POSTto insert into the database.hope this helps you.