Skip to content
Advertisement

How to get JavaScript variable value in PHP

I want the value of JavaScript variable which i could access using PHP. I am using the code below but it doesn’t return value of that variable in PHP.

JavaScript

JavaScript

this gives me the following error :-

JavaScript

Another php code i used which give empty value

JavaScript

When I echo it shows nothing.

Advertisement

Answer

You will need to use JS to send the URL back with a variable in it such as: http://www.site.com/index.php?uid=1

by using something like this in JS:

JavaScript

Then in the PHP code use $_GET:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement