smith.james0 Posted January 14, 2014 Share Posted January 14, 2014 I have the following code, the php bit below is to change $url between & and ? for the script if(isset($_GET[Category])){ $url = "&"; }else{ $url = "?"; } The $url is then put after the location.href+\" so it will read bee.php?lats or if there is another variable bee.php?something&lats <script> if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction,errorFunction); function successFunction(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; document.location = location.href+\"$url lats=\" + lat + \"&lons=\" + lon; } } function errorFunction(position) { var error = 'Yes'; document.location = location.href+\"$url error=\" + error; } </script> The problem I have is for the $url to work I have to have a space after it, which means I get bee.php? lats which doesn't work. How could I get around this? James Quote Link to comment https://forums.phpfreaks.com/topic/285369-url-problem/ Share on other sites More sharing options...
.josh Posted January 14, 2014 Share Posted January 14, 2014 so is that entire js block actually being echoed out by php and $url is a php var? or is $url a js var? If it's php then you can do this: document.location = location.href+\"{$url}lats=\" + lat + \"&lons=\" + lon; if $url is actually a js var at that point, you can do this: document.location = location.href+$url+\"lats=\" + lat + \"&lons=\" + lon; Quote Link to comment https://forums.phpfreaks.com/topic/285369-url-problem/#findComment-1465250 Share on other sites More sharing options...
Solution smith.james0 Posted January 14, 2014 Author Solution Share Posted January 14, 2014 Thanks for that, I used {$url} James Quote Link to comment https://forums.phpfreaks.com/topic/285369-url-problem/#findComment-1465259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.