if user is logged in only I have a section of my drupal website that I only want displayed to users that are logged in. So if they click on "My Page" link and the user is not logged in it should redirect them to a login screen. I have attempted to complete this task by using the following code.

&lt;?php
if (!user_is_logged_in()) drupal_goto('user/login'); ?&gt;


This doesn't seem to throw any coding errors but none of my links such as register, login etc work. I get an error that I have a redirect loop that will never complete. I cannot seem to find a good solution for completing this.
If you write down this piece of code outside any hook or function, it is normal that it loops because the user is always "not logged in".

However, if you've created your "page" through the admin menu system, as Parvind said, you can use Menu Access module or use that piece of code:

function hook_node_view($node, $view_mode) {
  if($node-&gt;nid == 'yournodeid" &amp;&amp; $view_mode == 'full') {
    if (!user_is_logged_in()) 
      drupal_goto('user/login');
  }
}


If you've created the node programmatically (hook_menu()), you can use access argument like this:

$items['testpage'] = array(
  'title' =&gt; 'Authenticated users',
  'page callback' =&gt; 'test_func',
  'description' =&gt; 'This page is accessible to authenticated users only',
  'access callback' =&gt; 'user_is_logged_in',
  'type' =&gt; MENU_CALLBACK,
);