Jump to content

Url problem


Go to solution Solved by 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.