while js code can be written in php. Markus Schuster. way save client side data without using forms. home > topics > javascript > questions > storing a javascript variable in a php string Post your question to a community of 468,214 developers. It's a kind of magic :) This may really make it hard to refactor code. you should include your Js code in your php file. you should write php page accepting json using post , save database. Variable is nothing it is just name of the memory location. I am a beginner in php and I have a url in the format of "localhost/page4.php#variable" where I get #variable like below : Sometimes we need to access the PHP variables in javascript or jquery for the use in the application. A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Passing PHP Arrays to JavaScript is very easy by using JavaScript Object Notation(JSON). How can I avoid this and store just the variable value? P.S. !!} Source: stackoverflow.com. Unlike before, we have used get method to send a JavaScript variable to PHP. Passing a variable is not that simple. It's quick & easy. Variables in PHP starts with a dollar($) sign, followed by the name of the variable. store the javascript variable to php variable. This code just sits there and works as needed when called in-line, but in an external javascript file (custom.js), how would main-block.php know how to use it … In PHP, there is always a limitation on pass PHP variable to the javascript file. Next Page Therefore, another important feature of variable scoping is static variable. How to store javascript value in php variable. variable.php