Jump to content

Url problem


smith.james0

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/285369-url-problem/
Share on other sites

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;
Link to comment
https://forums.phpfreaks.com/topic/285369-url-problem/#findComment-1465250
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.