Is there a way to pass a PHP value to JavaScript? I have a link generated within a JavaScript file that contains the following code:

jQuery(".url").append('&lt;a href='+ path +'/extra/home&gt;&lt;img src='+ pathimage +'&gt;&lt;/a&gt;');


I would like to alter the path variables when user is not logged. In Drupal terms this would look like: global $user; if (user-&gt;uid == 0) {..redirect page.} or global $user; return !(bool) $user-&gt;uid;

How can I use the $user-&gt;uid property with JavaScript code?
You're looking for drupal_add_js(). You can use it to pass data from PHP to JavaScript. Something like the following should suffice:

/**
 * Implementation of hook_init().
 */
function modulename_init() {
  if (!user_is_logged_in()) {
    drupal_add_js(array(
      'modulename' =&gt; array(
        'path' =&gt; $logged_out_path
      )
    ), 'setting');
  }
}


Note that I am calling this from within an implementation of hook_init(), but really you can do this anywhere, be it from a module or a theme. Also note that I have provided a sufficient namespace for the value to live (i.e. within 'modulename' => 'path'). This will make it clear from JavaScript's point of view exactly who owns the variable (i.e. which module it came from), but more importantly will help to prevent collisions with settings in other modules.

From JavaScript you can access the value of $logged_out_path like this:

var path = Drupal.settings.modulename.path;