My code executes as follow -
1) a Search page is loaded where session was already started, var-dump() shows the correct session info like username etc.
2) User enters a search value in a 3rd party script search box that forms part of my search page, I have no control over this script. 3) User presses the enter button, my javascript listens for the press event - key13.
4) The search criteria is then passed to a PHP page that adds values to the current session, which is then returned to the search page.
5)This is where the problem arises, when then user pressed entered, the 3rd party script executes additional shown data maps, it refreshes the entire page and my additional session data is lost. -By lost I mean the following - If I do not run the 3rd party script, I get the additional session data back into hidden inputs - var_dump() shows the data correctly on the search page, no problem, if I run the 3rd party script, the only session data that is returned is the login data from the beginning of the session.

I need this data to perform additional data enquiries, so my question is, how can I still keep the session data even if the 3rd party script is refreshing my page.

I tried to add it to its own form and used ajax to load only that form, did not work as it seems the script overrides my code. No errors is returned as all code works as it should, just the refresh that looses my returned data. I used alert to see if my javascript is running, no alerts where returned which means that mine was not running. Without the 3rd party script, I get a return on all the alerts.

I also tried to run the script in different parts of my page, still the same return.

I guess the "3rd party script" you are referring to is something that runs in the same server where you serve your site.

If so then the "I need this data to perform additional data enquiries, so my question is, how can I still keep the session data even if the 3rd party script is refreshing my page." has nothing to do with refreshing the page.

Probably this script just clears your session except for the login data (thats weird). Have you tried in step 4 to have your data also in other Session keys irrelevant to those that this script is about ? Does it clear those too ? .

If it clears all session data (except from login data - that is weird) you have two options , either read this script , understand where - when - why it is doing it and modify it , create a table that has a key the session id and fields the data you are interested in keeping , save them there in step 4 and then you can retrieve them whenever you want.

If you go with a table solution would be handy to add a timestamp field and delete every row that is let's say more than 60 days old (or what you session criteria are)

Thank you for your reply @JKon, much appreciated.

The 3rd party API/script is not run from the serving server (my own) but from theirs. I do not have any input capabilities to the javascript file either apart from some DOM elements.

When my page loads, this is the session data I receive, which is correct -

array(2) {
  ["username"]=>
  string(5) "Test2"
  ["user_role"]=>
  string(18) "Private Individual"
}

When I run the search item (using a Json GET to their API), using my own created search input text, this is the data returned, which is what I require for further use in page -

array(11) {
  ["username"]=>
  string(5) "Test2"
  ["user_role"]=>
  string(18) "Private Individual"
  ["yearmodel"]=>
  string(4) "2011"
  ["branddescription"]=>
  string(6) "Nissan"
  ["model"]=>
  string(10) "FAIRLADY Z"
  ["vin"]=>
  string(17) "JN12AAZ34Z07811234"
  ["enginesize"]=>
  string(7) "VQ37VHR"
  ["bodytype"]=>
  string(3) "R/S"
  ["transmission"]=>
  string(3) "7AT"
  ["ssdlevam"]=>
  string(65) "0838923013ef360e58e50880d14168cf:241f2147ce684477f7eb24ebd4blabla"
  ["linklevam"]=>
  string(144) "T3hlQW8xN0h4YlFSUlhwTEd0bjV0dktuNDhDWlphMHBML1BQdk1FNG13WTUrRmtzbDBrVytOWHR1YnA1Y000bEZ2aExoVk1HRkhxUDR0OFlzSDV4aEFrMExva2t3SkVTRDRNUG9vVUblabla"
}

When I use their script, it loads their page with all of its elements, when I run a session var_dump again, the output is as follow -

array(2) {
  ["username"]=>
  string(5) "Test2"
  ["user_role"]=>
  string(18) "Private Individual"
}

As you can see the data reverts back to the original session data. The link to the API is as follow -

<script id="levam_oem_catalog" src="https://widgets.levam.net/oem-widget/loader.js" lang="en" code="ulapkl" async></script>

Some more information might help - I grab some text from my datatable to poppulate a select element. User then selects the vehicle they need to search. As I have no control over the api, I copy the vin number to clipboard using javascript/jquery. It then gets pasted into their search input label. User presses ENTER and the page will "refresh" by loading the vehicle information from their database (not mine) via the Json GET call.

Once their page has loaded, the session data is missing, not sure how to keep the data for further use from the returned array as above. I did try another session id call, data is returned, once all their elements has loaded, the data array is empty.

You mentioned that I can keep the data by saving it, did you mean save this to a data table? then delete the data after a time period?

I would like to do this via a session if you might have a solution, otherwise I will have to take the long route and added stress to the server.

Sorry but I didn't quite get it , wou wrote:

When I run the search item (using a Json GET to their API), using my own created search input text, this is the data returned, which is what I require for further use in page -

when and how , exactly , do you put these data into session ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.