0

I have a somewhat theoretical question this time:

The situation (on a PHP website):

  1. members on a website can add cd's to their 'favorite list'
  2. onClick of the like-button, jQuery/ajax ads the cd to the favorite list
  3. another file renews the session array [favCDS]
  4. goal: the user always has his latest clicks updated real time, because live-data is generated from stored arrays)

The question:

Would it be possible to update a SESSION array of personal member values with a function, through a file running on the background, called by and updated through jQuery/ajax?

I imagine it would be updating it all in one file, but I wonder if you guys have any thoughts/ideas on this.

1 Answer 1

1

The PHP session persists even after scripts are finished running, so you don't need a PHP file running in the background on the server.

Example PHP file (called by the ajax function, assuming the ajax function submits a POST request with the CD's id):

update-favorite.php

$_SESSION['favCDS'][] = $_POST['cd-id'];

That way, when the user navigates to a new page, that page can preserve the favorite CDs by accessing this session array and generating HTML accordingly.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Jordan! But does this actually add the $_POST['cd-id'] to the $_SESSION['favCDS'][] then?
It adds $_POST['cd-id'] to $_SESSION['favCDs'] by means of the array[] = new item operator.
Thank you so much! You just made things much easier to build and make essential updates easy now. Again: thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.