- First, I put the array in localStorage into the variable.
var urls = JSON.parse(window.localStorage.getItem("urls"));
- Now I need to transfer this array to a variable in php in the same page.
- The ways I tried;
$urls = array();
for($i=0;$i<$count;$i++){
array_push($urls, "<script>document.write(urls[$i]);</script>");
}
Actually it kind of works.
<?php echo $urls[$i];?>
Normally when I say print to the screen, the variable works the way I want.
But
<a href="download.php?urls=<?php echo $urls[$i]; ?>" style="text-decoration: none">
When I say, the variable returns empty.
Or, when I say<img src = "<?php $urls [$i]; ?>
it also returns blank.AJAX
I tried very hard with Ajax and could not reach the result I wanted. My code is working. The problem is: I'm returning the variable with JS, but I can't use the variable over and over in php. I want to keep the variable in php and use it in php on the same page.
COOKIES
It worked for me perfectly. It meets what I want.
But
Data overload happened and crashed.
I do not intend to use it.
In short, I need to transfer an array in javascript to an array in PHP. I will use the array I transferred to PHP among php codes continuously.
Or isn't what I want is possible because php is a server-side language?
- NOTE: My knowledge of JavaScript or PHP is limited. The primary language I use is SWIFT. I have been working on this problem for a long time. Thank you for your support.