js+php. How can I save visitor settings?

Discussion in 'JavaScript' started by jag1, Jul 5, 2018.

  1. #1
    Hi I cant come up with how I can store visitors(not logged in visitors) settings. The settings will be applied to index.php

    I have come up with 2 solutions but none of them work.

    1. Cookies
    The settings size are too big to be able to be stored in cookies.

    2. localstorage.
    I cant grab localstorage items from PHP since the server cant read the localstorage items. The item settings need to be in index.phps PHP-code BEFORE index.php is loaded for the user since the settings data is used when renedring index.php from the backend. I cant get this to work, not even with AJAX since index.php get loaded before the AJAX data is being sent to the PHP.

    Is there any other way I can solve this?
     
    jag1, Jul 5, 2018 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    It might make a bit of overhead on the server, but you can use a session even if the user doesn't log in. So long as you have some mechanism to pass changes to the server when they happen, setting up sessions isn't a big deal.

    Every site I build is done using the 'one index.php to rule them all' approach, and the first thing that index.php does is a "session_start(); session_regenerate_id();" so I can do pretty much what you're asking about.

    Also handy for storing things like contact form hashes.
     
    deathshadow, Jul 13, 2018 IP