Domain and URL variables I have inherited some bad code in a Drupal 7.x site and it needs to be cleaned up.  Several places in the code the URL is hard-coded and I want to change that.  For example, in many of my javascript (.js) files I have something like this:

var url= 'http://dev3.ws.mysite.com/index.php/api/alerts_mix/x-api-key/blahhhhhhhhhzBkfqPTq4SWuCiLONePNfschNft';


In the PHP code I have the following:

     $url="http://dev3.ws.mysite.com/api/checkin/x-api-key/blahhhhhhhhhuRCMIWM0Nw0rM2cDK7tTJTPW?uid=11&amp;lt="


First question...is it OK to have the entire URL for the API (including the key) hard-coded or should we be calling this some other way?

Second...for both the js and PHP, what can I use in place of the HTTP and domain (http://dev3.ws.mysite.com) so it is a variable and gets those values from the config files so I don't need to change this every time when making a new dev site?
For configuration, like an API server URL, I'd suggest using Drupal variables. There are several ways to set the variable:


In the settings.php:


$conf['api_server'] = 'http://example.com';



With Drush:


drush vset api_server 'http://example.com'


Build an admin screen where you can set the value. (Probably overkill in this case.)


In your code where you need the URL, use variable_get():

$url = variable_get('api_server');


To access the value in JavaScript see: How to pass PHP variables to Javascript/jQuery?