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
x
// set global variable in javascript
profile_viewer_uid = 1;
JavaScript
// php code
$profile_viewer_uid=$_POST['profile_viewer_uid'];
this gives me the following error :-
JavaScript
A PHP Error was encountered
Severity: Notice
Message: Undefined index: profile_viewer_uid
Another php code i used which give empty value
JavaScript
$profile_viewer_uid = "<script language=javascript>document.write(profile_viewer_uid);</script>
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
window.location.href=”index.php?uid=1";
Then in the PHP code use $_GET:
JavaScript
$somevar = $_GET["uid"]; //puts the uid varialbe into $somevar