BR
asked on
assigning javascript variable to php variable
I have a javascript variable named "myvariable" . I want to assign this variable to a php variable
how can I do that?
how can I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
let's say using:
then in yourphp.php:
<script> var myvariable="something";
window.location.href = "yourphp.php?myvariable=" + myvariable;
</script>
then in yourphp.php:
<?php
$myphpvariable = isset($_GET['myvariable']) ? $_GET['myvariable'] : '';
echo "your variable = ". $myphpvariable;
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you all
ASKER
I'm ill now, i will reconsider the problem and how to make myself understood and reask the question on monday. Thank you
ASKER
Sorry i was answering another question. I don't know how did it happen. Sorry
<script type="text/javascript">
document.cookie = "myJavascriptVar =12345";
</script>
<?php
$phpVar = $_COOKIE['myJavascriptVar' ];
echo $phpVar;
?>
from https://stackoverflow.com/questions/21620133/how-to-assign-javascript-variable-value-to-php-variable
second answer it may be beneficial for you
document.cookie = "myJavascriptVar =12345";
</script>
<?php
$phpVar = $_COOKIE['myJavascriptVar'
echo $phpVar;
?>
from https://stackoverflow.com/questions/21620133/how-to-assign-javascript-variable-value-to-php-variable
second answer it may be beneficial for you
@Vikas Chauhan - posting answers from the "Expert Exchange Hater Site" is not really a great idea. Also the cookie is not available to PHP until the PHP page is then loaded using an HTTP request
@Michel Plungjan We can also follow another approach -
The approach is when site is getting loaded send device width from client side using ajax and save it in the database and then fetch where you want to use.
It might me be the solution m not sure ....
The approach is when site is getting loaded send device width from client side using ajax and save it in the database and then fetch where you want to use.
It might me be the solution m not sure ....
ASKER
<script> var myvariable="something"; </script>
what I want to do is like
<?php
echo $myphpvariable = '<script> here I need to call my variable but I don't know how </script>'