1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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.
    SEMrush
    Is there any other way I can solve this?
     
    jag1, Jul 5, 2018 IP
    SEMrush
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,603
    Likes Received:
    1,542
    Best Answers:
    223
    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 at 4:16 PM IP