Passing variables from Java Script to PHP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

freeflow

Established Member
Impact
13
Hi everyone! Can you tell me how to pass variables from Java Script to a PHP File?


This works with a .js file, but how can I make it work with php.

html + .js file

<body>
<h1>Example</h1>
<div id="geo" class="geolocation_data"></div>
<script type="text/JavaScript" src="geo.js"></script>
</body>
</html>



html + php file - How do I have to change the code above to make it work with
the php file below?

<?php

$geo = 'http://maps.google.com/maps/api/geocode/xml?latlng='.htmlentities(htmlspecialchars(strip_tags($_GET['latlng']))).'&sensor=true';
$xml = simplexml_load_file($geo);

...


Thanks for your help.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
•••
you can just echo the code that returns the value of the variable.
 
0
•••
php to javascript is easy since php runs before and you can echo the javascript, if you can make it work on ajax (best solution but a little more complex) then you are on the other side

when I need JS to PHP I usually make a cookie and retreive the data 1 click late or by running a second include with the echo
 
0
•••
dude just use a hidden value in the JS
 
0
•••
<script type="text/javascript">
var myVar = "<?PHP echo $phpVar; ?>";
</script>
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back