0

I want to use a localStorage variable in a PHP page. Very simple but "strange".

AJAX comes to mind. Whats the best form to do this?

Thanks

4
Contributors
6
Replies
19
Views
4 Years
Discussion Span
Last Post by pritaeas
0

you can also use session as session is easy to maintain. http://php.net/manual/en/function.session-start.php

Ive had problems with sessions in the past....plus I set this client side: I click on a checkbox, if the checkbox is true, something (cookie, localstorage, session, etc) must be stored that can be accessed EVERYWHERE on the site. Thats the problem I have with a cookie. Sessions get lost for some reason (problably related to the cookie problem) and thats why Im trying with localstorage....

0

To get the local storage variable to PHP you'll have to use an AJAX call. Whether you use a GET or POST is up to you. Personally, I'd choose a POST.

0

To get the local storage variable to PHP you'll have to use an AJAX call. Whether you use a GET or POST is up to you. Personally, I'd choose a POST.

What would be the best way to do this then?

example.php

<?php

echo "hi"
$var=getlocalstoragehere.php;
echo $var
?>

Lets say that the page I use. What would be the AJAX page?

0

Something like this if you use jQuery:

$.ajax({  
    type: "POST",  
    url: "example.php",  
    data: { storageValue: localStorage.getItem("yourValue"); }
});

In PHP you'd use $_POST['storageValue']

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.