Hi to all,

How can I redirect anonymous user to registration page when accessing members only page? I want to show upload-source-code
but when anonymous user click that link the message is

Access denied

--------------------------------------------------------------------------------

You are not authorized to access this page.

Thank you for any information

Comments

mariaGarry’s picture

Even though you solved your problem, I still feel I have to inform people about a much more...how do I put this...a much more no-need-for-plugin-ish way to do this (excuse that ridiculos word :D).
Heres all you need to do (or at least this worked for me):
Open your wordpress/wp-login.php file, and find this line:
$redirect_to = admin_url();

and replace it with this:

$redirect_to = get_option('siteurl');

There you go. A plugin might be much more comfortable to use and it might be a more convenient and easy and straightforward solution, but hey, use this if your plugin causes any kind of conflict or if you like to code yourself :D.

jaypabs’s picture

Hi,

I don't know what you mean but I am talking about drupal and not wordpress.

Thank you

WorldFallz’s picture

iirc, i think you can do this with the http://drupal.org/project/front module.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

jaypabs’s picture

Thanks for your help.

I just created a block to display a link based on anonymous or registered user.

here's the code I have created:

  global $user;
  if ($user->uid) {
    print "<a href='http://www.sourcecodester.com/upload-source-code'><font color='#FF0000'> Upload Source Code</font></a>";
  }
  else {
    print "<a href='http://www.sourcecodester.com/user/register'><font color='#FF0000'> Upload Source Code</font></a>";
  }

demo: www.sourcecodester.com